the seekTo() function doesn't work in VideoVie

2020-02-14 03:24发布

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.

标签: android
4条回答
做自己的国王
2楼-- · 2020-02-14 03:40

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

Checkout the VideoView source here for get more information.

查看更多
▲ chillily
3楼-- · 2020-02-14 03:42

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);
    }
};
查看更多
聊天终结者
4楼-- · 2020-02-14 03:45

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().

查看更多
Juvenile、少年°
5楼-- · 2020-02-14 03:46

Have you tried VideoView class from Vitamio library?

Vitamio

查看更多
登录 后发表回答