VideoView seekto() function extremely inconsistent

Vrashabh Irde picture Vrashabh Irde · Oct 17, 2012 · Viewed 10.7k times · Source

I am trying to Seek to a particular location in a video in Android and I am completely stuck because of the inconsistencies it is showing in its behaviour. Here's a list of things I ve done

  1. VideoView.Seekto goes to 5:19 for one video, 5:17 for one video and 5:32 for another for the same milliseconds(326000 ms)!
  2. Since VideoView does not support onSeekListener, I've modified the source VideoView and added support for it. Yet it does not pause and start seeking from where I want it to - there is always a lag! The onSeekListener is called immediately some 6 s before where I want it to stop. In many cases the seek bar shows the right time and suddenly jumps back a few seconds even though I am calling video.start from onSeekCompleteListener

Why is this so inconsistent ? Is there a definite way of seeking to where you want to go in milliseconds in videoview? I know I should use MediaPLayer + Surface but since VideoView is just a wrapper of the two I am modifying it at source but to no avail.

I am aware of this : http://code.google.com/p/android/issues/detail?id=9135 But is there any way to get around this and have a definite way of

1.) Seeking to the exact time in milliseconds

2.) Pausing and resuming at the exact time?

Answer

shivampip picture shivampip · Dec 12, 2017

You have to wait for the seeking to complete.

VideoView does not have a OnSeekCompleteListener() but you can access the MediaPlayer from the onPrepared method of the VideoView and then set the OnSeekCompleteListener, like this :

videoView.setOnPreparedListener(new OnPreparedListener() { 
    @Override 
    public void onPrepared(MediaPlayer mp) {

        mp.setOnSeekCompleteListener(new OnSeekCompleteListener() {
            @Override 
            public void onSeekComplete(MediaPlayer mp) {
                //Seek completed. Move seekbar
            } 
        }); 

    } 
});