I want to get the cover photo from audio file the application work for android 10+ and android 9 but in android 10 it give me an error
//this is my code
private byte[] getAlbumArt(String uri) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(uri);
byte[] art = retriever.getEmbeddedPicture();
retriever.release();
return art;
}
error :
Unknown bits set in runtime_flags: 0x8000
2020-09-18 22:19:53.826 23193-23193/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.MusicPlayer.musicplayervip, PID: 23193
java.lang.IllegalArgumentException
at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:77)
help, please 😘
this code didn't give a traceback and keep the app working but doesn't work perfectly it just ignores the image
private byte[] getAlbumArt(String uri) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
if (Build.VERSION.SDK_INT >= 14){
try {
retriever.setDataSource(uri, new HashMap<String, String>());
} catch (RuntimeException ex) {
// something went wrong with the file, ignore it and continue
}
}
else {
retriever.setDataSource(uri);
}
byte[] art = retriever.getEmbeddedPicture();
retriever.release();
return art;
}