Android的音乐播放歌曲加入后不重建索引播放歌曲、索引、音乐、Android

2023-09-05 02:39:33 作者:比纯牛奶还纯

我一直在试图创建一个简单的MP3下载器为Android。它所做的是连接的URL,下载跟踪和猜测的基础上名的ID3信息。我的应用程序中的问题是,一旦一首歌曲被下载,它不会立即显示在谷歌音乐应用程序,也没有在默认的音乐播放器应用程序。我甚至尝试了一些其他的没有运气,他们都不会重新索引它。

I've been trying to create a simple MP3 downloader for Android. All it does is connect to the URL, downloads the track and guesses the ID3 information based on the name. The problem with my application is that once a song is downloaded, it does not instantly show up in the Google Music app, nor in the default music player application. I even tried some other ones without luck, they all do not reindex it.

我发现的唯一的事情是,当我复制/移动在音乐文件夹的歌曲在我的SD卡SD卡的根目录下,它重新索引整个库正常。这给了我的想法,它可能不被提醒的任何文件的听众。

The only thing I noticed was that when I copied/moved the song from the Music folder on my SD card to the root of the SD card, it reindexed the entire library properly. This gave me the idea that it might not be alerting any file listeners.

我的问题是:如何将我能够保存一首歌曲的音乐文件夹,以及具有音乐播放器更新自己的指数?谢谢你在前进。

My question is: how would I be able to save a song to the Music folder, and having the music players update their indices? Thank you in advance.

推荐答案

您需要通知 MediaScanner 是一个新的文件已经被添加的,应被编入索引,使其显示在该 MediaStore

You need to notify the MediaScanner that a new file has been added and should be indexed so it shows up in the MediaStore.

的最简单的方法是发送一个广播一旦文件被下载:

The simplest way is to send a broadcast once the file has been downloaded:

Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);

http://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_SCANNER_SCAN_FILE

在假定其他音乐播放器,使用MediaStore,但它是一个不错的选择,他们这样做。

The assumes the "other music players" use the MediaStore, but it's a good bet that they do.

 
精彩推荐
图片推荐