MediaMetadataRetriever.setDataSource(Native Method) causes RuntimeException: status = 0x80000000

匿名 (未验证) 提交于 2019-12-03 02:27:02

问题:

I try to get some metadata informations from jpg file in my android app using android.media.MediaMetadataRetriever. Here is my code:

public long getDuration(String videoFilePath, Context context) {     File file = loadVideoFile(videoFilePath);     if (file == null) {         return -1;     }      MediaMetadataRetriever retriever = new MediaMetadataRetriever();     file.setReadable(true, false);     retriever.setDataSource(file.getAbsolutePath());     return getDurationProperty(retriever); } 

When I call setDataSource method it throws RuntimeException:

09-10 15:22:25.576: D/PowerManagerService(486): releaseWakeLock(419aa2a0): CPU_MIN_NUM , tag=AbsListViewScroll_5.0, flags=0x400 09-10 15:22:26.481: I/HtcModeClient(12704): handler message = 4011 09-10 15:22:26.481: E/HtcModeClient(12704): Check connection and retry 9 times. 09-10 15:22:27.681: W/dalvikvm(13569): threadid=1: thread exiting with uncaught exception (group=0x40bc92d0) 09-10 15:22:27.696: E/AndroidRuntime(13569): FATAL EXCEPTION: main 09-10 15:22:27.696: E/AndroidRuntime(13569): java.lang.RuntimeException: setDataSource failed: status = 0x80000000 09-10 15:22:27.696: E/AndroidRuntime(13569):    at android.media.MediaMetadataRetriever.setDataSource(Native Method) 09-10 15:22:27.696: E/AndroidRuntime(13569):    at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:66) 

And strange is that this fails only on HTC One X with Android 4.2.2. Applications works fine with other devices which has other android versions (for example 4.2.1).

Edit:

wow. Maybe it is about my wrong dependency in maven:

<dependency>     <groupId>com.google.android</groupId>     <artifactId>android</artifactId>     <version>4.1.1.4</version>     <scope>provided</scope> </dependency> 

But I can't find dependency for android 4.2.2. Where I can find it?

回答1:

Opening the file yourself and using the FileDescriptor seems to work better on API 10:

FileInputStream inputStream = new FileInputStream(file.getAbsolutePath()); retriever.setDataSource(inputStream.getFD()); inputStream.close(); 


回答2:

MediaMetadataRetriever doesn't seem to work consistently across all versions of Android. I recommend trying FFmpegMediaMetadataRetriever (Disclaimer: it's my project). It has the same interface as MediaMetadataRetriever:

FFmpegMediaMetadataRetriever retriever = new FFmpegMediaMetadataRetriever(); retriever.setDataSource(file.getAbsolutePath()); retriever.release(); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!