• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to update Genre name table in Mediastore with genre id

  • Thread starter Thread starter Deleted User
  • Start date Start date
D

Deleted User

Guest
I'm trying to update the genre tag of an audio file.

CODE

Code:
final Uri genreUri      = MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI;

String currentGenreName = MediaStore.Audio.Genres.NAME;

ContentValues values2 = new ContentValues();
values2.put(currentGenreName, genre);

String whereGenre = MediaStore.Audio.Genres._ID + "=?";
String[] whereVal2 = {Long.toString(genreID)};
resolver.update(genreUri, values2, whereGenre, whereVal2);
  • genre: value from edittext (new genre name).
  • genreID: genreID from selected audio file.
I'm not getting any errors, but the genre doesn't update in the MediaStore genre table.

Other tags like Title, artist, album and art are updated, only genre doesn't work.

Edit

resolver is the ContentResolver class that provides applications access to the content model.
Code:
ContentResolver resolver = context.getContentResolver();
 
Last edited by a moderator:
Put your code in [code][/code] tags, and show all relevant code. For example you don't show the declaration of variable 'resolver'. What is it?
 
Put your code in [code][/code] tags, and show all relevant code. For example you don't show the declaration of variable 'resolver'. What is it?
I edited the thread, can you check it?
 
I'm trying to update the genre tag of an audio file.

CODE
Code:
final Uri genreUri = MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI;

String currentGenreName = MediaStore.Audio.Genres.NAME;

ContentValues values2 = new ContentValues();
values2.put(currentGenreName, genre);

String whereGenre = MediaStore.Audio.Genres._ID + "=?";
String[] whereVal2 = {Long.toString(genreID)};
resolver.update(genreUri, values2, whereGenre, whereVal2);
  • genre: value from edittext (new genre name).
  • genreID: genreID from selected audio file.
  • resolver: ContentResolver resolver = c.getContentResolver();
I'm not getting any errors, but the genre doesn't update in the MediaStore genre table.

Other tags like Title, artist, album and art are updated, only genre doesn't work.

I also can't find any information about updating the genre name in an audio file, I only managed to do it with the tags above.

EDIT

Code I used for editing the title, artist, albumname and year tags and this works fine so I figured i had to do the same for the genre name because I have the genre id.

Code:
final Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

ContentResolver resolver = c.getContentResolver();

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 currentGenreID   = MediaStore.Audio.Genres._ID;
String currentGenreName = MediaStore.Audio.Genres.NAME;
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);
 
Back
Top Bottom