英文:
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 >= 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;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论