Code example for MediaPlayer

Methods: getAudioSessionIdsetOnCompletionListener

0
    { 
      throw new NullPointerException("Cannot link to null MediaPlayer");
    } 
 
    // Create the Visualizer object and attach it to our media player. 
    mVisualizer = new Visualizer(player.getAudioSessionId());
    // [1] is the max capture size (phone dependent) 
    mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);
 
    // Pass through Visualizer data to this class 
    Visualizer.OnDataCaptureListener captureListener = new Visualizer.OnDataCaptureListener()
    { 
      @Override 
      public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes,
          int samplingRate)
      { 
        // will never get called 
      } 
 
      @Override 
      public void onFftDataCapture(Visualizer visualizer, byte[] bytes,
          int samplingRate)
      { 
        updateVisualizerFFT(bytes);
      } 
    }; 
 
    // if you take the max capture rate and divide it by 2 you get the max sampling rate to retain 
    // the correct frequencies per Nyquist Theory 
    mVisualizer.setDataCaptureListener(captureListener,
        Visualizer.getMaxCaptureRate() / 2, false, true);
 
    // Enabled Visualizer and disable when we're done with the stream 
    mVisualizer.setEnabled(true);
    player.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
    { 
      @Override 
      public void onCompletion(MediaPlayer mediaPlayer)
      { 
        mVisualizer.setEnabled(false);