@Override public boolean dispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); if (event.getRepeatCount() == 0 && event.isDown() && (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_SPACE)) { doPauseResume(); show(sDefaultTimeout); if (mPauseButton != null) { mPauseButton.requestFocus(); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP) { if (mPlayer.isPlaying()) { mPlayer.pause(); updatePausePlay(); } return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { // don't show the controls for volume adjustment return super.dispatchKeyEvent(event); } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) { hide(); return true; } else { show(sDefaultTimeout); } return super.dispatchKeyEvent(event); }
public void onPrepared(MediaPlayer mp) { mCurrentState = STATE_PREPARED; // modify by lxj // Get the capabilities of the player for this stream // Metadata data = mp.getMetadata(MediaPlayer.METADATA_ALL, // MediaPlayer.BYPASS_METADATA_FILTER); // // if (data != null) { // mCanPause = !data.has(Metadata.PAUSE_AVAILABLE) // || data.getBoolean(Metadata.PAUSE_AVAILABLE); // mCanSeekBack = !data.has(Metadata.SEEK_BACKWARD_AVAILABLE) // || data.getBoolean(Metadata.SEEK_BACKWARD_AVAILABLE); // mCanSeekForward = !data.has(Metadata.SEEK_FORWARD_AVAILABLE) // || data.getBoolean(Metadata.SEEK_FORWARD_AVAILABLE); // } else { // mCanPause = mCanSeekBack = mCanSeekForward = true; // } mCanPause = mCanSeekBack = mCanSeekForward = true; if (mOnPreparedListener != null) { mOnPreparedListener.onPrepared(mMediaPlayer); } if (mMediaController != null) { mMediaController.setEnabled(true); } mVideoWidth = mp.getVideoWidth(); mVideoHeight = mp.getVideoHeight(); int seekToPosition = mSeekWhenPrepared; // mSeekWhenPrepared may be changed after seekTo() call if (seekToPosition != 0) { seekTo(seekToPosition); } if (mVideoWidth != 0 && mVideoHeight != 0) { // Log.i("@@@@", "video size: " + mVideoWidth +"/"+ mVideoHeight); getHolder().setFixedSize(mVideoWidth, mVideoHeight); if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) { // We didn't actually change the size (it was already at the size // we need), so we won't get a "surface changed" callback, so // start the video here instead of in the callback. if (mTargetState == STATE_PLAYING) { start(); if (mMediaController != null) { mMediaController.show(); } } else if (!isPlaying() && (seekToPosition != 0 || getCurrentPosition() > 0)) { if (mMediaController != null) { // Show the media controls when we're paused into a video and make 'em stick. mMediaController.show(0); } } } } else { // We don't know the video size yet, but should start anyway. // The video size might be reported to us later. if (mTargetState == STATE_PLAYING) { start(); } } }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (mIsPrepared && keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_CALL && keyCode != KeyEvent.KEYCODE_ENDCALL && mMediaPlayer != null && mMediaController != null) { if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) { if (mMediaPlayer.isPlaying()) { pause(); mMediaController.show(); } else { start(); mMediaController.hide(); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP && mMediaPlayer.isPlaying()) { pause(); mMediaController.show(); } else { toggleMediaControlsVisiblity(); } } return super.onKeyDown(keyCode, event); }
public void onPrepared(MediaPlayer mp) { // briefly show the mediacontroller mIsPrepared = true; if (mOnPreparedListener != null) { mOnPreparedListener.onPrepared(mMediaPlayer); } if (mMediaController != null) { mMediaController.setEnabled(true); } mVideoWidth = mp.getVideoWidth(); mVideoHeight = mp.getVideoHeight(); if (mVideoWidth != 0 && mVideoHeight != 0) { // Log.i("@@@@", "video size: " + mVideoWidth +"/"+ // mVideoHeight); getHolder().setFixedSize(mVideoWidth, mVideoHeight); if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) { // We didn't actually change the size (it was already at the // size // we need), so we won't get a "surface changed" callback, // so // start the video here instead of in the callback. if (mSeekWhenPrepared != 0) { mMediaPlayer.seekTo(mSeekWhenPrepared); mSeekWhenPrepared = 0; } if (mStartWhenPrepared) { mMediaPlayer.start(); mStartWhenPrepared = false; if (mMediaController != null) { mMediaController.show(); } } else if (!isPlaying() && (mSeekWhenPrepared != 0 || getCurrentPosition() > 0)) { if (mMediaController != null) { // Show the media controls when we're paused into a // video and make 'em stick. mMediaController.show(0); } } } } else { // We don't know the video size yet, but should start anyway. // The video size might be reported to us later. if (mSeekWhenPrepared != 0) { mMediaPlayer.seekTo(mSeekWhenPrepared); mSeekWhenPrepared = 0; } if (mStartWhenPrepared) { mMediaPlayer.start(); mStartWhenPrepared = false; } } }
@Override public void show() { mMediaController.show(); if (mVideoView != null) { mVideoView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } }
@Override public boolean onTouchEvent(MotionEvent event) { if (mIsMediaReadyToBePlayed) { mMediaController.show(); } return false; }
private void toggleMediaControlsVisiblity() { if (mMediaController.isShowing()) { mMediaController.hide(); } else { mMediaController.show(); } }
@Override public boolean dispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); final boolean uniqueDown = event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN; if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_SPACE) { if (uniqueDown) { doPauseResume(); show(sDefaultTimeout); if (mPauseButton != null) { mPauseButton.requestFocus(); } } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) { if (uniqueDown && !mPlayer.isPlaying()) { mPlayer.start(); updatePausePlay(); show(sDefaultTimeout); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) { if (uniqueDown && mPlayer.isPlaying()) { mPlayer.pause(); updatePausePlay(); show(sDefaultTimeout); } return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE || keyCode == KeyEvent.KEYCODE_CAMERA) { // don't show the controls for volume adjustment return super.dispatchKeyEvent(event); } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) { if (uniqueDown) { hide(); } return true; } show(sDefaultTimeout); return super.dispatchKeyEvent(event); }
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: show(0); // show until hide is called break; case MotionEvent.ACTION_UP: show(sDefaultTimeout); // start timeout break; case MotionEvent.ACTION_CANCEL: hide(); break; default: break; } return true; }
@Override public void onPrepared(MediaPlayer mp) { mediaPlayer.start(); mediacontroller.setMediaPlayer(this); mediacontroller.setAnchorView(findViewById(R.id.surfaceView)); mediacontroller.show(); }
public void onPrepared(MediaPlayer mp) { // briefly show the mediacontroller mIsPrepared = true; if (mOnPreparedListener != null) { mOnPreparedListener.onPrepared(mMediaPlayer); } if (mMediaController != null) { mMediaController.setEnabled(true); } mVideoWidth = mp.getVideoWidth(); mVideoHeight = mp.getVideoHeight(); if (mVideoWidth != 0 && mVideoHeight != 0) { // Log.i("@@@@", "video size: " + mVideoWidth +"/"+ mVideoHeight); getHolder().setFixedSize(mVideoWidth, mVideoHeight); if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) { // We didn't actually change the size (it was already at the size // we need), so we won't get a "surface changed" callback, so // start the video here instead of in the callback. if (mSeekWhenPrepared != 0) { mMediaPlayer.seekTo(mSeekWhenPrepared); } if (mStartWhenPrepared) { mMediaPlayer.start(); if (mMediaController != null) { mMediaController.show(); } } else if (!isPlaying() && (mSeekWhenPrepared != 0 || getCurrentPosition() > 0)) { if (mMediaController != null) { mMediaController.show( 0); // show the media controls when we're paused into a video and make 'em // stick. } } } } else { Log.d( "VideoView", "Couldn't get video size after prepare(): " + mVideoWidth + "/" + mVideoHeight); // The file was probably truncated or corrupt. Start anyway, so // that we play whatever short snippet is there and then get // the "playback completed" event. if (mStartWhenPrepared) { mMediaPlayer.start(); } } }
public void onClick(View v) { int pos = mPlayer.getCurrentPosition(); pos += 15000; // milliseconds mPlayer.seekTo(pos); setProgress(); show(sDefaultTimeout); }
@Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { Log.d(TAG, "player state " + playbackState); if (playbackState == ExoPlayer.STATE_READY) { shutterView.setVisibility(View.GONE); mediaController.show(0); } }
@Override public void run() { if (DEBUG) { Log.d(TAG, "Show video controller"); } if (controller != null) { controller.show(); } }
public void onPrepared(MediaPlayer mediaplayer) { Log.d(TAG, "onPrepared called"); mIsMediaReadyToBePlayed = true; if (mMediaPlayer != null && mIsMediaReadyToBePlayed) { start(); if (mMediaController != null) mMediaController.show(); mProgressBar.setVisibility(View.GONE); } }
@Override public boolean onTouchEvent(MotionEvent event) { /* * the MediaController will hide after 3 seconds - tap the screen to * make it appear again */ mediacontroller.show(); return false; }
public void onPrepared(MediaPlayer mp) { mCurrentState = STATE_PREPARED; if (mOnPreparedListener != null) { mOnPreparedListener.onPrepared(mMediaPlayer); } if (mMediaController != null) { mMediaController.setEnabled(true); } mVideoWidth = mp.getVideoWidth(); mVideoHeight = mp.getVideoHeight(); int seekToPosition = mSeekWhenPrepared; // mSeekWhenPrepared may be changed after seekTo() call if (seekToPosition != 0) { seekTo(seekToPosition); } if (mVideoWidth != 0 && mVideoHeight != 0) { // Log.i("@@@@", "video size: " + mVideoWidth +"/"+ mVideoHeight); getHolder().setFixedSize(mVideoWidth, mVideoHeight); if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) { // We didn't actually change the size (it was already at the size // we need), so we won't get a "surface changed" callback, so // start the video here instead of in the callback. if (mTargetState == STATE_PLAYING) { start(); if (mMediaController != null) { mMediaController.show(); } } else if (!isPlaying() && (seekToPosition != 0 || getCurrentPosition() > 0)) { if (mMediaController != null) { // Show the media controls when we're paused into a video and make 'em stick. mMediaController.show(0); } } } } else { // We don't know the video size yet, but should start anyway. // The video size might be reported to us later. if (mTargetState == STATE_PLAYING) { start(); } } }
public void onStopTrackingTouch(SeekBar bar) { mDragging = false; setProgress(); updatePausePlay(); show(sDefaultTimeout); // Ensure that progress is properly updated in the future, // the call to show() does not guarantee this because it is a // no-op if we are already showing. mHandler.sendEmptyMessage(SHOW_PROGRESS); }
@Override protected void onPostExecute(Uri pResult) { super.onPostExecute(pResult); try { if (isCancelled()) return; if (pResult == null) { throw new RuntimeException("Invalid NULL Url."); } mVideoView.setVideoURI(pResult); if (isCancelled()) return; // TODO: add listeners for finish of video mVideoView.setOnCompletionListener( new OnCompletionListener() { public void onCompletion(MediaPlayer pMp) { if (isCancelled()) return; OpenYouTubePlayerActivity.this.finish(); } }); if (isCancelled()) return; final MediaController lMediaController = new MediaController(OpenYouTubePlayerActivity.this); mVideoView.setMediaController(lMediaController); lMediaController.show(0); // mVideoView.setKeepScreenOn(true); mVideoView.setOnPreparedListener( new MediaPlayer.OnPreparedListener() { public void onPrepared(MediaPlayer pMp) { if (isCancelled()) return; OpenYouTubePlayerActivity.this.mProgressBar.setVisibility(View.GONE); OpenYouTubePlayerActivity.this.mProgressMessage.setVisibility(View.GONE); } }); if (isCancelled()) return; mVideoView.requestFocus(); mVideoView.start(); } catch (Exception e) { Log.e(this.getClass().getSimpleName(), "Error playing video!" + pResult, e); if (!mShowedError) { showErrorAlert(); } } }
public void onStartTrackingTouch(SeekBar bar) { show(3600000); mDragging = true; // By removing these pending progress messages we make sure // that a) we won't update the progress while the user adjusts // the seekbar and b) once the user is done dragging the thumb // we will post one of these messages to the queue again and // this ensures that there will be exactly one message queued up. mHandler.removeMessages(SHOW_PROGRESS); }
@Override public boolean dispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); if (event.getRepeatCount() == 0 && event.isDown() && (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_PLAYPAUSE || keyCode == KeyEvent.KEYCODE_SPACE)) { doPauseResume(); show(sDefaultTimeout); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { // don't show the controls for volume adjustment return super.dispatchKeyEvent(event); } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) { hide(); } else { show(sDefaultTimeout); } return super.dispatchKeyEvent(event); }
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { mSurfaceWidth = w; mSurfaceHeight = h; if (mMediaPlayer != null && mIsPrepared && mVideoWidth == w && mVideoHeight == h) { if (mSeekWhenPrepared != 0) { mMediaPlayer.seekTo(mSeekWhenPrepared); mSeekWhenPrepared = 0; } mMediaPlayer.start(); if (mMediaController != null) { mMediaController.show(); } } }
@Override // POINT: 컨트롤러를 다시 보여 준다. public boolean onTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { if (controller.isShowing()) { controller.hide(); // surfaceView.setLayoutParams(new FrameLayout.LayoutParams( // videoWidth, videoHeight)); } else { controller.show(); // surfaceView.setLayoutParams(new FrameLayout.LayoutParams( // videoWidth, videoHeight - 75)); } } return false; }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.menuButton: if (((ScrollView) mVideoList.getParent()).getVisibility() == View.INVISIBLE) { ((ScrollView) mVideoList.getParent()).setVisibility(View.VISIBLE); ((ScrollView) mVideoList.getParent()).bringToFront(); controller.show(); } else ((ScrollView) mVideoList.getParent()).setVisibility(View.INVISIBLE); Log.e("TAG", "menu Button"); break; case R.id.videoList: break; default: break; } }
public void onPrepared(MediaPlayer mp) { Log.v(LOGTAG, "onPrepared Called"); videoWidth = mp.getVideoWidth(); videoHeight = mp.getVideoHeight(); // 스크린 사이즈 구하기 DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int screenWidth = metrics.widthPixels; int screenHeight = metrics.heightPixels; if (videoWidth > screenWidth || videoHeight > screenHeight) { float heightRatio = (float) videoHeight / (float) screenHeight; float widthRatio = (float) videoWidth / (float) screenWidth; if (heightRatio > 1 || widthRatio > 1) { if (heightRatio > widthRatio) { videoHeight = (int) Math.ceil((float) videoHeight / (float) heightRatio); videoWidth = (int) Math.ceil((float) videoWidth / (float) heightRatio); } else { videoHeight = (int) Math.ceil((float) videoHeight / (float) widthRatio); videoWidth = (int) Math.ceil((float) videoWidth / (float) widthRatio); } } } else { videoHeight = screenHeight; videoWidth = screenWidth; } // surfaceView.setLayoutParams(new FrameLayout.LayoutParams(videoWidth, // videoHeight - 75)); mp.start(); // 미디어 플레이어의 컨트롤러를 설정하고 보이기 controller.setMediaPlayer(this); controller.setAnchorView(this.findViewById(R.id.controllerView)); controller.setEnabled(true); controller.show(); }
@Override public void onDrawnToSurface(Surface surface) { shutterView.setVisibility(View.GONE); mediaController.show(0); }
public void onClick(View v) { doPauseResume(); show(sDefaultTimeout); }
private void showControls() { mediaController.show(0); // debugRootView.setVisibility(View.VISIBLE); }
private void f() { if ((a()) && (o.getVisibility() != 0)) { p.show(); } }
@Override public void show(int timeout_ms) { mMediaController.show(timeout_ms); }