I have already seen many questions about Android MediaPlayer issues, most of them due to the seekTo() function. Now I tried to use it, and it worked as expected: bad!
This feature seems very inconsistent, especially when we want to provide its functionality while the video is paused. In my case, I have videos from 30 to 60 frames and I want to play them one by one - without this delay, which MediaMetadataRetriever.getFrameAtTime () provides.
The problem I am facing is when I call seekTo() , it does not update the SurfaceView . It only works for the first time, after which the SurfaceView remains unchanged, it never updates.
I heard rumors that seekTo() only works with a minimum interval of 1 second, but I tested with a longer video and finding the second one didnβt work either.
code
mSurfaceHolder = mSurfaceView.getHolder(); mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); mSurfaceHolder.addCallback(this); mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDisplay(mSurfaceHolder); mMediaPlayer.setOnSeekCompleteListener(new OnSeekCompleteListener() { @Override public void onSeekComplete(MediaPlayer mp) {
private void seekTo(int targetMs) { mMediaPlayer.start(); mMediaPlayer.seekTo(targetMs); }
Please note that due to a known error regarding the use of this function, a workaround is used when pausing the video:
Launch the video;
Call seekTo() ;
- Pause it on
onSeekComplete() .
source share