我正在视频中播放视频。完成后,我必须开始一个CountdownTimer。 videoview的setOnCompletionListener方法被调用两次,因此启动计时器的代码会运行两次。
我是否需要调用任何其他方法来完成任务?
代码:
VideoView videoView;
private MediaController controller;
private void setupView(View view){
videoView = (VideoView) view.findViewById(R.id.videoView);
controller = new MediaController(getActivity());
controller.setAnchorView(videoView);
videoView.setMediaController(null);
videoView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
videoView.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
stopVideoViewTimer();
startExcerciseDetailTimer();
}
});
playCurrentVideo();
}
private void playCurrentVideo() {
if (prepareVideo()) {
roundTimeLayoutCombos.setVisibility(View.GONE);
excerciseTimerLayout.setVisibility(View.GONE);
restTimeLayout.setVisibility(View.GONE);
videoLayout.setVisibility(View.VISIBLE);
updateExerciseLayout();
videoView.start();
}
}
private Boolean prepareVideo() {
Boolean prepared = false;
String filePath = Environment.getExternalStorageDirectory()+"/folder/xyz.mp4";
videoView.setVideoURI(Uri.parse(filePath));
videoView.requestFocus();
prepared = true;
return prepared;
}