27

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?

Vrashabh Irde
  • 14,129
  • 6
  • 51
  • 103
  • im interested on this post. do you have an answer or explanation for this? – sara brown Oct 29 '12 at 03:45
  • Basically this is the issue - http://code.google.com/p/android/issues/detail?id=9135 let me know if you need specifics – Vrashabh Irde Oct 29 '12 at 06:12
  • 1
    The inaccuracy is in the media file itself, I believe. [This guy explains it well](http://stackoverflow.com/a/6908256/931277). – dokkaebi Dec 15 '12 at 04:23
  • I have the same problem! I can't start player from any position between 1st and 10th second! It starts playing either from the very beginning, or from the 10th second. Very weird. (Android 2.3.4, LG) – kolobok Aug 04 '13 at 11:11
  • Hi @Slartibartfast got any solution...i have same problem please reply if you have got any sol on this. Thanks – user3207655 May 12 '15 at 11:21
  • @user3207655 if [this](http://stackoverflow.com/a/11939135/1276636) works for you then please comment back. I guess it should do the trick. I might be adding it to my app too, regardless of your commenting back or not ;) – Sufian May 14 '15 at 12:23
  • 1
    Hi @Sufian yes it has worked for me – user3207655 May 15 '15 at 09:03
  • possible duplicate of [the seekTo() function doesn't work in VideoView](http://stackoverflow.com/questions/10328854/the-seekto-function-doesnt-work-in-videoview) – Sufian May 15 '15 at 10:17
  • 1
    Well my question is more to do with the inconsistency of video view time seek, not with seek working/not working which the other answer seems to suggest. Although I don't remember what I did with this.I think we accepted the minor delta seek errors at that time. So to me I'm not sure if the other answers provide a way, that given a time X, seek to that point exactly – Vrashabh Irde May 15 '15 at 11:38
  • If you're willing to invest a bit of time, you can look into Exoplayer. It will give you much better seeking accuracy and control. – mbonnin Dec 12 '17 at 19:36

4 Answers4

1

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
            } 
        }); 

    } 
}); 
shivampip
  • 2,004
  • 19
  • 19
0

10 years later and I came across the same question exactly.

Any way, for me, the solution was to use the mediaPlayer from inside VideoView (Android Oreo 8.0+):

enter image description here

Explanation:

videoView default seekTo function use mediaPlayer default seekTo function (source)

mediaPlayer default seekTo overload is the same as seekTo(long, int) with SEEK_PREVIOUS_SYNC mode, you should use SEEK_PREVIOUS_SYNC only if you want to seek to a sync frame that has a timestamp earlier than or the same as milliseconds given,

However, SEEK_CLOSEST will seek to a frame that may or may not be a sync frame but is closest to or the same as milliseconds.

Nirel
  • 1,855
  • 1
  • 15
  • 26
-1

I know this is not the proper solution to your question but take a look into this library that is being made over the Google's default video view

https://github.com/brianwernick/ExoMedia

It has all the functionality and more that is being supported by default video view.

You can use this video view and emVideoView.seekTo(1000); to jump to 1000 millisecond in the video. You can also have setOnSeekCompletionListener to do process when seek complete.

Rudrik Patel
  • 676
  • 6
  • 13
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/18265533) – drhagen Dec 15 '17 at 11:44
  • Sorry, Edited answer for better understanding rather then just pasting the URL. – Rudrik Patel Dec 15 '17 at 12:00
-3

I solved this problem like this

the seekTo() function doesn't work in VideoView

Community
  • 1
  • 1
J.J. Kim
  • 1,845
  • 1
  • 16
  • 21