Code example for MediaPlayer

Methods: getAudioSessionIdsetOnCompletionListener

0
		 
		// Create the Visualizer object and attach it to our media player. 
		if (player == null)
			mVisualizer = new Visualizer(0);
		else 
			mVisualizer = new Visualizer(player.getAudioSessionId());
 
		mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);
 
		// Pass through Visualizer data to VisualizerView 
		Visualizer.OnDataCaptureListener captureListener = new Visualizer.OnDataCaptureListener() {
			@Override 
			public void onWaveFormDataCapture(Visualizer visualizer,
					byte[] bytes, int samplingRate) {
				updateVisualizer(bytes);
			} 
 
			@Override 
			public void onFftDataCapture(Visualizer visualizer, byte[] bytes,
					int samplingRate) {
				updateVisualizerFFT(bytes);
			} 
		}; 
 
		mVisualizer.setDataCaptureListener(captureListener,
				Visualizer.getMaxCaptureRate() / 2, true, true);
 
		// Enabled Visualizer and disable when we're done with the stream 
		mVisualizer.setEnabled(true);
		if (player != null)
			player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
				@Override 
				public void onCompletion(MediaPlayer mediaPlayer) {
					mVisualizer.setEnabled(false);
				} 
			});