8

There is a problem in my application,I want to use the seekTo() function with VideoView like this:

videoView.seekTo(time);
videoView.start();

It works well in android 2.2 ,but doesn't work in android 2.3 or higher version... Some body will tell me why? It troubles me for serval days.

Wowo Ot
  • 1,362
  • 13
  • 21
Laolizi
  • 256
  • 1
  • 2
  • 7
  • are you sure you're waiting for long enough to decide that it's not working? on one of my LG phones, for example, seekTo takes like forever. whereas on my other LG phone, it's actually not that bad – David T. Nov 04 '13 at 23:51
  • You can use MediaController Class in Android Which makes controlling of entire VideoView easy. – Ansh Rochan Oct 01 '20 at 19:58

4 Answers4

4

The call to VideoView.start() should be made only after the seek has completed. The call to VideoView.seekTo() initiates a seek but unfortunately VideoView does not support OnSeekCompleteListener needed to notify the seek is actually done.

You can customize VideoView to support OnSeekCompleteListener as shown in my answer to 7990784.

Then you can register to receive onSeekComplete() by calling setOnSeekCompleteListener(). Your implementation of the listener should then call VideoView.start().

Community
  • 1
  • 1
Peter Tran
  • 1,626
  • 1
  • 17
  • 26
  • 2
    This is quite simply the best answer. Easy to implement and actually works. I get the reference to the `MediaPlayer` in `onPrepared()` and use it to do the rest (set `OnSeekListener` and call `seekTo()`). – Sufian Jun 04 '15 at 10:44
1

For proper operation of the method seekTo(),the video state should be in PlaybackState.

Checkout the VideoView source here for get more information.

Iulia Barbu
  • 1,522
  • 12
  • 25
1

Have you tried VideoView class from Vitamio library?

Vitamio

valerybodak
  • 4,195
  • 2
  • 42
  • 53
0

This solution should work. The problem may be that the mediaplayer inside videoView has not been created.

It's easy to test, by changing the orientation of the device. That's how I tested it.

videoView.setOnPreparedListener(onPreparedListener);
private MediaPlayer.OnPreparedListener onPreparedListener = new MediaPlayer.OnPreparedListener() {
    public void onPrepared(MediaPlayer mp) {
        mp.seekTo(videoPosition);
    }
};
Bandreid
  • 2,727
  • 28
  • 47
BactaTank
  • 164
  • 2
  • 10