Visualizer 媒体播放器链接
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)。对替代品有什么建议吗?