这是我的代码,我在其中播放链接中提供的视频,但是在特定时间点单击时,它会再次从 0 位置开始。我想从用户选择的任何位置播放视频。我正在使用存储在下面给定链接中的 webm 视频。视频以播放/暂停功能播放,但是我无法在流式传输时寻找视频中的特定位置。
String videolinkurl = "techslides.com/demos/sample-videos/small.webm";
videoView = (VideoView) findViewById(R.id.videoView);
// Set the media controller buttons
if (mediaController == null) {
mediaController = new MediaController(sessionRecordingVideo.this);
// Set the videoView that acts as the anchor for the MediaController.
mediaController.setAnchorView(videoView);
// Set MediaController for VideoView
videoView.setMediaController(mediaController);
}
videoView.requestFocus();
videoView.setVideoURI(Uri.parse(videolinkurl));
final Boolean canSeekForward = videoView.canSeekForward();
System.out.println(canSeekForward);
final Boolean canSeekBackward = videoView.canSeekBackward();
System.out.println(canSeekBackward);
videoView.start();
// When the video file ready for playback.
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mediaPlayer) {
videoView.seekTo(position);
if (position == 0) {
videoView.start();
}
else if (canSeekForward && canSeekBackward){
int currentPosition = videoView.getCurrentPosition();
videoView.seekTo(currentPosition);
videoView.start();
}
else {
videoView.pause();
}
}
});
videoView.setOnInfoListener(new MediaPlayer.OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mediaPlayer, int what, int extra) {
return true;
}
});
videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
return true;
}
});
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mediaPlayer) {
videoView.stopPlayback();
}
});