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

huangapple go评论74阅读模式
英文:

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

问题

以下是翻译好的内容:

我想从音频文件中获取封面照片。该应用适用于安卓10及以上版本以及安卓9,但在安卓10上出现错误。

//这是我的代码

 private byte[] getAlbumArt(String uri) {
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        retriever.setDataSource(uri);
        byte[] art = retriever.getEmbeddedPicture();
        retriever.release();
        return art;
    }

错误信息:

运行时标志中设置了未知位:0x8000
2020-09-18 22:19:53.826 23193-23193/? E/AndroidRuntime: 致命异常: main
    进程: com.MusicPlayer.musicplayervip, PID: 23193
    java.lang.IllegalArgumentException
        在 android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:77) 处

请帮忙,谢谢 😘

英文:

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 😘

答案1

得分: 1

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) {
            // 文件出现问题,忽略并继续
        }
    } else {
        retriever.setDataSource(uri);
    }
    byte[] art = retriever.getEmbeddedPicture();
    retriever.release();
    return art;
}
英文:

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 &gt;= 14){
            try {
                retriever.setDataSource(uri, new HashMap&lt;String, String&gt;());
            } 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;
    }

huangapple
  • 本文由 发表于 2020年9月19日 06:34:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63963589.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定