奇怪的是,我在真实设备上尝试过,效果很好。仅在模拟器上由于某种原因它不起作用。
我什至尝试降低 api 级别,但仍然无法正常工作。
我尝试只更改歌曲名称,每次出现此行时,即使我没有更改专辑封面。
table album_art has no column named relative_path
知道为什么它可以在真实设备上运行而没有任何问题而不是在模拟器上运行吗?
使用新值更新 MediaStore 中的表时出现 Logcat 错误。
E/SQLiteLog: (1) table album_art has no column named relative_path
E/SQLiteDatabase: Error inserting _data=/storage/emulated/0/Music/_.thumbnails/1574144730622.jpg album_id=3 relative_path=Music/.thumbnails/
android.database.sqlite.SQLiteException: table album_art has no column named relative_path (code 1 SQLITE_ERROR): , while compiling: INSERT INTO album_art(_data,album_id,relative_path) VALUES (?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:986)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:593)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:590)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:61)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:33)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1597)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1468)
at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:3213)
at com.android.providers.media.MediaProvider.insert(MediaProvider.java:2903)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:309)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:154)
at android.os.Binder.execTransactInternal(Binder.java:1021)
at android.os.Binder.execTransact(Binder.java:994)
更改 mp3 信息的代码
public void changeMp3Tags(Context c, long songID, long albumID,
String title, String artist, String album, String file_path, String year) throws Exception {
try {
final Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
final Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, albumID);
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 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);
ContentValues valuesAlbum = new ContentValues();
valuesAlbum.put(currentAlbumID, albumID);
valuesAlbum.put(currentAlbumData, file_path);
//Update song info.
String where = MediaStore.Audio.Media._ID + "=?";
String[] whereVal = {Long.toString(songID)};
resolver.update(musicUri, values, where, whereVal);
//Update albumArt.
resolver.delete(albumArtUri, null,null);
resolver.insert(sArtworkUri, valuesAlbum);
}catch (Exception e){
Log.e(TAG, "Exception caught when changing MP3 tags!", e);
throw new Exception();
}
}