我正在使用 MediaMetadataRetriever 通过视频帧创建缩略图,但我在Logcat中收到此消息:
E/MediaMetadataRetrieverJNI(14060): getFrameAtTime: videoFrame 是一个空指针
这是我的代码:
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
Uri videoURI = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.video_one);
retriever = new MediaMetadataRetriever();
retriever.setDataSource(mContext, videoURI);
Bitmap bitmap = retriever.getFrameAtTime(100000,MediaMetadataRetriever.OPTION_CLOSEST_SYNC );
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
holder.imageView.setImageDrawable(drawable);
holder.progressBar.setVisibility(View.INVISIBLE);
} catch (Exception e) {
e.printStackTrace();
}
然后我尝试了这个FFmpegMediaMetadataRetriever 库,但它在 Logcat 中产生了这个:
01-19 12:38:33.371: D/dalvikvm(20821): Trying to load lib /data/data/wseemann.media.demo/lib/libavutil.so 0x41733c90
01-19 12:38:33.371: D/dalvikvm(20821): Added shared lib /data/data/wseemann.media.demo/lib/libavutil.so 0x41733c90
01-19 12:38:34.121: W/System.err(20821): java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFFF
01-19 12:38:34.121: W/System.err(20821): at wseemann.media.FFmpegMediaMetadataRetriever.setDataSource(Native Method)
01-19 12:38:34.121: W/System.err(20821): at wseemann.media.FFmpegMediaMetadataRetriever.setDataSource(FFmpegMediaMetadataRetriever.java:243)
01-19 12:38:34.121: W/System.err(20821): at wseemann.media.demo.FMMRDemo.onCreate(FMMRDemo.java:50)
01-19 12:38:34.121: W/System.err(20821): at android.app.Activity.performCreate(Activity.java:5188)
01-19 12:38:34.121: W/System.err(20821): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
01-19 12:38:34.121: W/System.err(20821): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
01-19 12:38:34.121: W/System.err(20821): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
01-19 12:38:34.121: W/System.err(20821): at android.app.ActivityThread.access$700(ActivityThread.java:140)
01-19 12:38:34.121: W/System.err(20821): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
01-19 12:38:34.121: W/System.err(20821): at android.os.Handler.dispatchMessage(Handler.java:99)
01-19 12:38:34.121: W/System.err(20821): at android.os.Looper.loop(Looper.java:137)
01-19 12:38:34.121: W/System.err(20821): at android.app.ActivityThread.main(ActivityThread.java:4921)
01-19 12:38:34.121: W/System.err(20821): at java.lang.reflect.Method.invokeNative(Native Method)
01-19 12:38:34.121: W/System.err(20821): at java.lang.reflect.Method.invoke(Method.java:511)
01-19 12:38:34.121: W/System.err(20821): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-19 12:38:34.121: W/System.err(20821): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-19 12:38:34.121: W/System.err(20821): at dalvik.system.NativeStart.main(Native Method)
这是我的代码:
ImageView imageView= (ImageView) findViewById(R.id.imageView1);
try {
FFmpegMediaMetadataRetriever retriever = new FFmpegMediaMetadataRetriever();
AssetFileDescriptor afd;
afd = getAssets().openFd("video_one.mp4");
retriever.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
Bitmap bitmap = retriever.getFrameAtTime(100000,FFmpegMediaMetadataRetriever.OPTION_CLOSEST_SYNC );
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
imageView.setImageDrawable(drawable);
retriever.release();
} catch (Exception e) {
e.printStackTrace();
}
接下来我尝试使用 SDcard 路径但仍然是相同的 logcat