How not to seek to keyframes

2019-03-31 17:59发布

I've tried to find a solution to seek frame by frame (not only to keyframes) in my android app.

  1. approach: A simple VideoView of the android sdk:
    Here I've got a onSeekCompleteListener of the base class MediaPlayer from the onPreparedListener of VideoView and pause the playback right after started it and moved to a preferred position.
    Problem: Only seeks to keyframes!

  2. approach: MediaMetaRetriever: I have got something like this:

    MediaMetadataRetriever retriever;
    long Position;
    ImageView video;
    TextView lbPosition;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        video = (ImageView)findViewById(R.id.imVideo);
        lbPosition = (TextView)findViewById(R.id.lbPosition);
        bnTake = (Button)findViewById(R.id.bntake);
        retriever.setDataSource(this, Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.vid));
    
        video.setOnClickListener(new ImageView.OnClickListener() {
            @Override
            public void onClick(View arg0) {
               Position += 100000;
               Bitmap frame = retriever.getFrameAtTime(Position, MediaMetadataRetriever.OPTION_CLOSEST);
               video.setImageBitmap(frame);
               lbPosition.setText(String.valueOf(Position));
           }            
        });
    
        bnTake.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
                startActivityForResult(takeVideoIntent, 123123);
            }
        }); 
    }
    

When I use OPTION_CLOSESTS in retriever.getFrameAtTime it gives me a getFrameAtTime: videoFrame is a NULL pointer error. When I don't use this option, it goes through keyframes.

Maybe possible solutions:

  1. approach: Record video with more keyframes. If I would record the video with an higher keyframe rate in my android app, could that be a solution? Is this possible?

  2. approach (I haven't tried!): I've heard something of video player 3rd party libraries for android that use FFMPEG. Is there any library that can seek while in pause state and update the position for the video on the screen?

1条回答
仙女界的扛把子
2楼-- · 2019-03-31 18:18
登录 后发表回答