다른 비디오 파일이 표시된 활동이 있습니다. 비디오 파일을 클릭하면 VideoView에서 비디오를 재생하는 다른 활동으로 이동합니다.Android - VideoView를 종료하려면 BACK을 두 번 눌러야합니다.
내 문제는이 활동을 끝내고 이전으로 돌아가고 싶을 때 뒤로 돌아 가기 위해 뒤로 버튼을 두 번 클릭해야한다는 것입니다. 한 번만 클릭하면 동영상 재생이 다시 시작되고 두 번째 시도에서 화면을 종료 할 수 있습니다. 나는 로그 캣 "다시 비디오 플레이어 누르면"활동이 종료되지 않습니다에서 볼 수 있지만,
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Log.d(Constants.LOG_TAG, "back pressed in videoplayer");
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
그리고 :
은 그 때 나는이 시도. 다시 버튼을 두 번 눌러야합니다.편집 : 이것은 가장 관련있는 소스 코드입니다. 그러나 비디오는 인터넷에서 재생되며, Mediacontroller를 사용하지 않고 대신 자신의 레이아웃을 정의하고 videoview 콘트롤에 연결합니다.
public class VideoPlayer extends Activity implements OnClickListener, OnCompletionListener,
OnSeekBarChangeListener, OnPreparedListener, OnTouchListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_view);
// Gets the position of clicked video, from an ArrayList of video urls.
selectedVideo = getPosition();
// the play button
play = (ImageButton) findViewById(R.id.play);
play.setOnClickListener(this);
videoView = (VideoView) findViewById(R.id.videoView);
videoView.setOnCompletionListener(this);
videoView.setOnPreparedListener(this);
videoView.setOnTouchListener(this);
// the url to play
String path = videoUris.get(selectedVideo);
videoView.setVideoPath(getPath(path));
}
/**
* Play or Pause the current video file.
*
* If the video is paused, then invoking this method should start it. If the video is already playing, then the
* video should pause.
*/
private void play() {
if (!isVideoStarted) {
isVideoStarted = true;
videoView.start();
play.setImageResource(R.drawable.video_pause);
videoSeekBar.post(updateSeekBarRunnable);
} else if (isVideoStarted) {
isVideoStarted = false;
pause();
}
}
/**
* Start playing back a video file with the specified Uri.
*/
private void startPlayback() {
String path = videoUris.get(selectedVideo);
videoView.setVideoPath(getPath(path));
videoView.start();
}
/**
* Stops the currently playing video. (The SeekBar position is reset to beginning, 0.)
*/
private void stopPlayback() {
videoView.stopPlayback();
}
/**
* Pause the currently playing video. (The SeekBar remains in its position.)
*/
private void pause() {
videoView.pause();
@Override
public void onPrepared(MediaPlayer mp) {
play();
}
}
당신은 u는이 비디오를 재생하는 r에 어떻게 보일 수 있는가? –
코드가 추가되었습니다. –