Question

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?

Was it helpful?

Solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top