Code example for MediaPlayer

Methods: setDataSourcesetDisplaysetOnCompletionListenersetOnPreparedListener

0
 
		@Override 
		public void onCreate(SurfaceHolder holder) {
			super.onCreate(holder);
			holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
			mp = new MediaPlayer();
			mp.setDisplay(new MySurfaceHolder(holder));
			mp.setOnPreparedListener(new OnPreparedListener() {
				@Override 
				public void onPrepared(MediaPlayer mp) {
					mp.start();
				} 
			}); 
			try { 
				mp.setDataSource(MovieLiveWallpaperService.this, Uri
				        .parse("content://media/external/video/media/1"));
			} catch (Exception e) {
				Log.e(TAG, "error");
			} 
			mp.setOnCompletionListener(new OnCompletionListener() {
				@Override 
				public void onCompletion(MediaPlayer mp) {
					mp.stop();
				} 
			}); 
Contextual code suggestions in your IDE  Get Codota for Java