简体   繁体   中英

Android 10 : API 29 - java.lang.IllegalArgumentException at android.media.MediaMetadataRetriever.setDataSource

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

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