MediaMetadataRetrieverJNI(14060):getFrameAtTime:videoFrame是一个NULL指针(Android)

时间:2015-01-19 07:06:35

标签: android android-videoview mediametadataretriever

我使用MediaMetadataRetriever通过视频框架创建缩略图,但我在 Logcat 中收到此消息:

  

E / MediaMetadataRetrieverJNI(14060):getFrameAtTime:videoFrame是一个NULL指针

这是我的代码:

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 Library,但它在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

2 个答案:

答案 0 :(得分:1)

尝试使用MediaMetadataRetriever.OPTION_CLOSEST_SYNC代替MediaMetadataRetriever.OPTION_NEXT_SYNC

如果这不起作用,那么您应该尝试使用FFmpegMediaMetadataRetriever库,因为MediaMetadataRetriever与所有API都不兼容。

修改

尝试使用SD卡文件:

FFmpegMediaMetadataRetriever retriever = new  FFmpegMediaMetadataRetriever();
try {
retriever.setDataSource("mnt/sdcard/video.mp4"); //file's path
Bitmap bitmap = retriever.getFrameAtTime(100000,FFmpegMediaMetadataRetriever.OPTION_CLOSEST_SYNC );
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
i.setImageDrawable(drawable);

} catch (Exception e) {
e.printStackTrace();
}
finally{
retriever.release();
}

答案 1 :(得分:0)

根据我的经验,内置MediaMetadataRetriver很少有效。请改为尝试like this