Code example for Visualizer

Methods: setCaptureSize, setDataCaptureListener, setEnabled

2
    { 
      throw new NullPointerException("Cannot link to null MediaPlayer");
    } 
 
    // Create the Visualizer object and attach it to our media player. 
    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);
    player.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
    { 
      @Override 
      public void onCompletion(MediaPlayer mediaPlayer)
      {