如何为Android 2.3.3录音机创建Visualizer

时间:2013-03-18 06:29:54

标签: android

Visualizer Mediaplayer链接

public void link(MediaPlayer player)
  {
    if(player == null)
    {
      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);

  }

如何为Android Audio Recorder 2.3.3创建Visualizer?我希望能够做到这样的事情:

public void link(AudioRecorder recorder)
{

// Create the Visualizer object and attach it to our media player.
mVisualizer = new Visualizer(recorder.getAudioSessionId());

但我的问题是recorder.getAudioSessionId()方法仅适用于API级别16(Jellybean)及以上版本,而我的目标是Android 2.3.3(Gingerbread)。有关替代品的任何建议吗?

0 个答案:

没有答案