Code example for MediaPlayer: Playing audio and video

Methods: preparesetDataSourcesetOnCompletionListenersetOnPreparedListenerstart, setSurface

0
					int width, int height) {
 
				Surface s = new Surface(surface);
 
				try { 
					mMediaPlayer = new MediaPlayer();
					mMediaPlayer.setDataSource(path);
					mMediaPlayer.setSurface(s);
 
					mMediaPlayer
							.setOnPreparedListener(new OnPreparedListener() {
 
								private MediaPlayer mp_;
 
								@Override 
								public void onPrepared(MediaPlayer mp) {
 
									// MediaController mediaController = new 
									// MediaController( 
									// getActivity()); 
									// mVideoView.setMediaController(mediaController); 
 
									// mVideoView.requestFocus(); 
									// mVideoView.setKeepScreenOn(true); 
 
									// mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
									// mMediaPlayer.start(); 
									// mp_.start(); 
 
									// mp_ = mp; 
									// mp_.setLooping(true); 
 
									// mVideoView.animate().rotation(200).alpha((float) 
									// 0.5) 
									// .scaleX(0.2f).scaleY(0.2f).setDuration(2000); 
 
									r = new Runnable() {
										@Override 
										public void run() { 
											for (VideoListener l : listeners) {
												l.onTimeUpdate(mp_
														.getCurrentPosition(),
														mp_.getDuration());
											} 
											handler.postDelayed(this, 1000);
										} 
									}; 
 
									handler.post(r);
								} 
							}); 
 
					mMediaPlayer
							.setOnCompletionListener(new OnCompletionListener() {
 
								@Override 
								public void onCompletion(MediaPlayer mp) {
 
								} 
							}); 
 
					mMediaPlayer.prepare();
					mMediaPlayer.start();
 
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
				} catch (SecurityException e) {
					e.printStackTrace();