Code example for MediaPlayer

Methods: prepareAsyncsetAudioStreamTypesetDataSourcesetDisplaysetOnPreparedListener

0
		Log.d(TAG, "Play video on full, path: " + path);
		File videFile = new File(path);
        FileInputStream fis;
		try { 
			fis = new FileInputStream(videFile);
	        mMediaPlayer.setDataSource(fis.getFD());
	        mMediaPlayer.setDisplay(sHolder);
	         
	        mMediaPlayer.prepareAsync();
	         
	        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);
		} 
	}