private void fixMediaSize() { if (mMediaPlayer == null || !mIsMediaReadyToBePlayed) return; int width = mMediaPlayer.getVideoWidth(); int height = mMediaPlayer.getVideoHeight(); Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); int screenWidth = size.x; int screenHeight = size.y; android.view.ViewGroup.LayoutParams videoParams = mMediaView.getLayoutParams(); if (width > 0 && height > 0) { Log.i(TAG, "Video is: " + width + " x " + height); if (width > height) { videoParams.width = screenWidth; videoParams.height = screenWidth * height / width; } else { videoParams.width = screenHeight * width / height; videoParams.height = screenHeight; } } else { videoParams.width = 0; videoParams.height = 0; } Log.i(TAG, "Setting dimensions to: " + videoParams.width + " x " + videoParams.height); mMediaView.setLayoutParams(videoParams); }
public void onPrepared(MediaPlayer mp) { Log.d("onPrepared"); mCurrentState = STATE_PREPARED; mTargetState = STATE_PLAYING; if (mOnPreparedListener != null) mOnPreparedListener.onPrepared(mMediaPlayer); if (mMediaController != null) mMediaController.setEnabled(true); mVideoWidth = mp.getVideoWidth(); mVideoHeight = mp.getVideoHeight(); mVideoAspectRatio = mp.getVideoAspectRatio(); long seekToPosition = mSeekWhenPrepared; if (seekToPosition != 0) seekTo(seekToPosition); if (mVideoWidth != 0 && mVideoHeight != 0) { setVideoLayout(mVideoLayout, mAspectRatio); if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) { if (mTargetState == STATE_PLAYING) { start(); if (mMediaController != null) mMediaController.show(); } else if (!isPlaying() && (seekToPosition != 0 || getCurrentPosition() > 0)) { if (mMediaController != null) mMediaController.show(0); } } } else if (mTargetState == STATE_PLAYING) { start(); } }
private void initSizeSurfaceView() { /*int videoWidth = player.getVideoWidth(); int videoHeight = player.getVideoHeight(); Point screenSize = new Point(); getWindowManager().getDefaultDisplay().getSize(screenSize); android.view.ViewGroup.LayoutParams lp = surfaceView.getLayoutParams(); lp.width = screenSize.x; lp.height = (int) (((float)videoHeight / (float)videoWidth) * (float)screenSize.x); surfaceView.setLayoutParams(lp);*/ int videoWidth = player.getVideoWidth(); int videoHeight = player.getVideoHeight(); float videoProportion = (float) videoWidth / (float) videoHeight; Point screenSize = new Point(); getWindowManager().getDefaultDisplay().getSize(screenSize); float screenProportion = (float) screenSize.x / (float) screenSize.y; android.view.ViewGroup.LayoutParams lp = surfaceView.getLayoutParams(); if (videoProportion > screenProportion) { lp.width = screenSize.x; lp.height = (int) ((float) screenSize.x / videoProportion); } else { lp.width = (int) (videoProportion * (float) screenSize.y); lp.height = screenSize.y; } surfaceView.setLayoutParams(lp); }
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { Log.d("onVideoSizeChanged: (%dx%d)", width, height); mVideoWidth = mp.getVideoWidth(); mVideoHeight = mp.getVideoHeight(); mVideoAspectRatio = mp.getVideoAspectRatio(); if (mVideoWidth != 0 && mVideoHeight != 0) setVideoLayout(mVideoLayout, mAspectRatio); }
public int getVideoHeight() { if (mInitialized) return mPlayer.getVideoHeight(); return 0; }