Code example for SurfaceView

Methods: getHeight, getLayoutParams, getWidth, setLayoutParams

0
	@Override 
	public void onPrepared(MediaPlayer mp) {
		preferences = PreferenceManager.getDefaultSharedPreferences(context);
		 
		android.view.ViewGroup.LayoutParams lp = setupAspectRatio(surfaceView, plexAspectRatio);
		surfaceView.setLayoutParams(lp);
		mediaController.setEnabled(true);
 
		if (resumeOffset > 0 && SerenityApplication.getVideoPlaybackQueue().isEmpty()) {
			AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
					context, android.R.style.Theme_Holo_Dialog);
 
			alertDialogBuilder.setTitle("Resume Video");
			alertDialogBuilder
					.setMessage("Resume the video from " + TimeUtil.formatDuration(resumeOffset)  + " or restart?")
					.setCancelable(false) 
					.setPositiveButton("Resume", 
							new DialogInterface.OnClickListener() {
 
								@Override 
								public void onClick(DialogInterface dialog,
										int which) {
									if (!mediaPlayer.isPlaying()) {
										mediaPlayer.start();
									} 
									mediaPlayer.seekTo(resumeOffset);
									setMetaData(); 
								} 
							}) 
					.setNegativeButton("Restart", 
							new DialogInterface.OnClickListener() {
 
								@Override 
								public void onClick(DialogInterface dialog,
										int which) {
									mediaPlayer.start();
									setMetaData(); 
								} 
							}); 
 
			alertDialogBuilder.create();
			alertDialogBuilder.show();
			return; 
		} else { 
			mediaPlayer.start();			
			setMetaData(); 
		} 
	} 
	 
	 
	/** 
	 *  
	 */ 
	protected void setMetaData() { 
		new WatchedVideoAsyncTask().execute(videoId);
		boolean showOSD = preferences.getBoolean("internal_player_osd", true);
		if (showOSD) {
			mediaController.show(SerenitySurfaceViewVideoActivity.CONTROLLER_DELAY);
		} 
		if (progressReportingHandler != null) {
			progressReportingHandler.postDelayed(progressRunnable, 5000);
		} 
	} 
	 
	/** 
	 * Setup the aspect ratio for the SurfaceView 
	 *  
	 * @return 
	 */ 
	protected android.view.ViewGroup.LayoutParams setupAspectRatio(SurfaceView surfaceView, String plexAspectRatio) {
		RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) surfaceView
				.getLayoutParams();
 
		SharedPreferences prefs = PreferenceManager
				.getDefaultSharedPreferences(context);
		boolean preferPlexAspectRatio = prefs.getBoolean("plex_aspect_ratio",
				false); 
 
		int surfaceViewHeight = surfaceView.getHeight();
		int surfaceViewWidth = surfaceView.getWidth();
 
		float videoWidth = mediaPlayer.getVideoWidth();
		float videoHeight = mediaPlayer.getVideoHeight();
 
		float ratioWidth = surfaceViewWidth / videoWidth;