Code example for MediaPlayer: Playing audio and video

Methods: getVideoHeightgetVideoWidthseekTostart

0
	         
	        mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
				@Override 
				public void onPrepared(MediaPlayer mp) {
					onCancel(); 
					mMediaPlayer.start();
					setSurfaceViewScale(); 
					mMediaPlayer.seekTo(position);
					mc.setMediaPlayer(getMediaPlayerControl());
					mc.setAnchorView(video);
					 
					Handler handler = new Handler();
			        handler.post(new Runnable() {
			            public void run() { 
			                mc.setEnabled(true);
			                try{ 
			                	mc.show();
			                } catch (BadTokenException e) {
								Log.w(TAG,"Can't show media controller, activity may not running yet.",e);
							} 
			            } 
			        }); 
				} 
			}); 
	        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
		} catch (Exception e) {
			Log.e(TAG,"Problem with input stream!",e);
		} 
	} 
	 
	private void setSurfaceViewScale(){ 
		 
		int width = video.getWidth();
		int height = video.getHeight();
		float boxWidth = width;
		float boxHeight = height;
 
		float videoWidth = mMediaPlayer.getVideoWidth();
		float videoHeight = mMediaPlayer.getVideoHeight();
 
		float wr = boxWidth / videoWidth;
		float hr = boxHeight / videoHeight;
		float ar = videoWidth / videoHeight;