Android Audiofx Visualizer的初始化错误-3

时间:2017-04-27 17:01:36

标签: android android-audiorecord

初始化Visualizer时出现以下错误:

java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -3
at android.media.audiofx.Visualizer.<init>(Visualizer.java:218)

这是我的代码:

public void play(String path, Context context) throws IOException {
    Log.i(TAG, "Playing sound: " + path);
    AssetFileDescriptor afd = context.getAssets().openFd(
            "sounds/" + path + ".mp3");
    player.reset();
    player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
    player.prepare();

    mVisualizer = new Visualizer(player.getAudioSessionId());
    mVisualizer.setEnabled(true);
    mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);
    mVisualizer.setDataCaptureListener(this, Visualizer.getMaxCaptureRate() / 2, true, false);

    player.start();
}

错误发生在:new Visualizer(player.getAudioSessionId());

我已经在Manifiest中添加了RECORD_AUDIO权限,正如它在answer中所说:

<uses-permission android:name="android.permission.RECORD_AUDIO" />

0 个答案:

没有答案