简体   繁体   中英

Update the album art in android mediastore?

I want to set my image as the album art for a audio mp3 file. I know the album id ,when i update, the application throw java.lang.UnsupportedOperationException.

Here is my code for update..

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();
}

My 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)

You must delete the previous artwork first (if it already exist):

Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");    
int deleted = getContentResolver().delete(ContentUris.withAppendedId(sArtworkUri, album_id), null, null);

and then insert it again:

ContentValues values = new ContentValues();
values.put("album_id", album_id);
values.put("_data", file_url);
Uri num_updates = getContentResolver().insert(sArtworkUri, values);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM