我想将我的图像设置为音频mp3文件的专辑封面。我知道专辑ID,当我更新时,应用程序抛出java.lang.UnsupportedOperationException。
这是我的更新代码。
ContentValues values_art=new ContentValues();
values_art.put(MediaStore.Audio.AlbumColumns.ALBUM_ART, img_path);
int b=getContentResolver().update(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, values_art,MediaStore.Audio.Albums.ALBUM_ID + "=?", new String[]{album_id});
if(b !=0){
Toast.makeText(getApplicationContext(), "Successfuly Image Updated", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getApplicationContext(), "Not Image Updated", Toast.LENGTH_LONG).show();
}
我的Logcat:
05-11 00:14:33.063: E/AndroidRuntime(4046): FATAL EXCEPTION: main
05-11 00:14:33.063: E/AndroidRuntime(4046): java.lang.UnsupportedOperationException: Unknown or unsupported URL: content://media/external/audio/albums
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:169)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.content.ContentProviderProxy.update(ContentProviderNative.java:507)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.content.ContentResolver.update(ContentResolver.java:1022)
05-11 00:14:33.063: E/AndroidRuntime(4046): at fsoft.farhad.mediaeditor.AudioTabActivity$4.onClick(AudioTabActivity.java:89)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.view.View.performClick(View.java:4212)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.view.View$PerformClick.run(View.java:17476)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.os.Handler.handleCallback(Handler.java:800)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.os.Handler.dispatchMessage(Handler.java:100)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.os.Looper.loop(Looper.java:194)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.app.ActivityThread.main(ActivityThread.java:5371)
05-11 00:14:33.063: E/AndroidRuntime(4046): at java.lang.reflect.Method.invokeNative(Native Method)
05-11 00:14:33.063: E/AndroidRuntime(4046): at java.lang.reflect.Method.invoke(Method.java:525)
05-11 00:14:33.063: E/AndroidRuntime(4046): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
05-11 00:14:33.063: E/AndroidRuntime(4046): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
05-11 00:14:33.063: E/AndroidRuntime(4046): at dalvik.system.NativeStart.main(Native Method)
最佳答案
您必须先删除先前的图稿(如果已经存在):
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
int deleted = getContentResolver().delete(ContentUris.withAppendedId(sArtworkUri, album_id), null, null);
然后再次插入:
ContentValues values = new ContentValues();
values.put("album_id", album_id);
values.put("_data", file_url);
Uri num_updates = getContentResolver().insert(sArtworkUri, values);
关于java - 更新Android Mediastore中的专辑封面?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23584598/