Reputation:
I want to play video in arbitrary time for videoview in Android
_player.setVideoURI(Uri.parse(uri));
MediaController mc = new MediaController(this);
_player.setMediaController(mc);
_player.start();
Now I want set time: 10:20 to seek file and play it (10 min and 20 sec)
Upvotes: 1
Views: 1919
Reputation: 3034
You have to wait until the video is prepared to seek.
int seekTimeMs = (10 * 60 + 20) * 1000; // 10:20
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.seekTo(seekTimeMs);
}
});
Upvotes: 0
Reputation: 54682
see VideoView.seekTo(int msec) method
Also note one thing from the doc
The playback position can be adjusted with a call to seekTo(int). Although the asynchronuous seekTo(int) call returns right way, the actual seek operation may take a while to finish, especially for audio/video being streamed. When the actual seek operation completes, the internal player engine calls a user supplied OnSeekComplete.onSeekComplete() if an OnSeekCompleteListener has been registered beforehand via setOnSeekCompleteListener(OnSeekCompleteListener).
Upvotes: 1