Search code examples
javaandroidandroid-contentresolvermediastore

Should i use mp3 tag editor or insert new values in MediaStore?


This is the code i use for updating song information.

 String currentTitle     = MediaStore.Audio.Media.TITLE;
 String currentArtist    = MediaStore.Audio.Media.ARTIST;
 String currentAlbumID   = MediaStore.Audio.Media.ALBUM_ID;
 String currentAlbum     = MediaStore.Audio.Media.ALBUM;
 String currentAlbumData = MediaStore.Audio.Media.DATA;
 String currentYear      = MediaStore.Audio.Media.YEAR;

 ContentValues values = new ContentValues();
 values.put(currentTitle, title);
 values.put(currentArtist, artist);
 values.put(currentAlbum, album);
 values.put(currentYear, year);

 //Update song info.
 String where = MediaStore.Audio.Media._ID + "=?";
 String[] whereVal = {Long.toString(songID)};
 resolver.update(musicUri, values, where, whereVal);

But i'm not sure if this is the right way to do it, it works fine, when i edit the songs this way and close the application and restart it, the song is updated with the new values.

title, artist, album and year are the new values i get from an EditText and then i pass it as parameters to my method for updating it in the MediaStore.

I also read something about jAudioTagger for editing the TAGS, but i had some problems with this library so i would like to know if this is also a good way to update song information.

Thanks


Solution

  • You are comparing apples to oranges. What you are doing now is saving the info to a local database. This provides quick sorting and searching on your device. It does not attach the info to the music file itself, so if you copy song to another device, or share it with someone else, they will not have the info.
    jAudioTagger puts the info into the file itself. Thus it will be there even when you copy to other device or share with someone else. But searches and sorting will be slow, as you have to open each file and then sort. So the correct way is to do both. Save the info to the file itself, using jAudioTagger or the like, then cache it to database as you are doing now, for quick access.