I've tried to find a solution to seek frame by frame (not only to keyframes) in my android app.
approach: A simple
VideoView
of theandroid sdk
:
Here I've got aonSeekCompleteListener
of the base classMediaPlayer
from theonPreparedListener
ofVideoView
andpause
the playback right after started it and moved to a preferred position.
Problem: Only seeks to keyframes!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:
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?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?