Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android music player not reindexing after song addition

Tags:

java

android

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.

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.

like image 850
Bart Pelle Avatar asked Jun 30 '13 13:06

Bart Pelle


People also ask

Why my downloaded songs are not showing in music player android?

Another reason for songs not showing in Play Music might be due to a corrupted memory card. Remove the card and then insert it again. Check if the songs are visible. In case the songs are stored on the internal memory, remove the card and check without it.

Why are my downloaded songs not showing on music player?

Go to Settings > Apps > Media Storage > Clear data. Hope it works. It worked in my case.

How do you refresh your music player?

To refresh the list of your music you do following: Go into settings->manage apps->ALL services. Scroll down and select "Media Storage." Then hit the "Clear Data" icon. Good to know from the same source: You must then reboot your phone, and at boot the phone runs the media update service in the background.


1 Answers

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

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

like image 188
Ken Wolf Avatar answered Oct 16 '22 16:10

Ken Wolf