Code example for MediaPlayer: Playing audio and video

Methods: getVideoHeightgetVideoWidthisPlayingstart

0
		seekBarProgress.setMax(duration);
		textViewLength.setText(Utils.durationInSecondsToString(duration));
		progressBarWait.setVisibility(View.GONE);
 
		// Get the dimensions of the video 
		int videoWidth = player.getVideoWidth();
		int videoHeight = player.getVideoHeight();
		float videoProportion = (float) videoWidth / (float) videoHeight;
		Log.i(TAG, "VIDEO SIZES: W: " + videoWidth + " H: " + videoHeight + " PROP: " + videoProportion);
 
		// Get the width of the screen 
		int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
		int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
		float screenProportion = (float) screenWidth / (float) screenHeight;
		Log.i(TAG, "VIDEO SIZES: W: " + screenWidth + " H: " + screenHeight + " PROP: " + screenProportion);
 
		// Get the SurfaceView layout parameters 
		android.view.ViewGroup.LayoutParams lp = surfaceViewFrame.getLayoutParams();
 
		if (videoProportion > screenProportion) {
			lp.width = screenWidth;
			lp.height = (int) ((float) screenWidth / videoProportion);
		} else { 
			lp.width = (int) (videoProportion * (float) screenHeight);
			lp.height = screenHeight;
		} 
 
		// Commit the layout parameters 
		surfaceViewFrame.setLayoutParams(lp);
 
		// Start video 
		if (!player.isPlaying()) {
			player.start();
			updateMediaProgress(); 
			linearLayoutMediaController.setVisibility(View.VISIBLE);
			hideMediaController(); 
		} 
		surfaceViewFrame.setClickable(true);