gpt4 book ai didi

java - android.media.AudioRecord;错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:21:09 28 4
gpt4 key购买 nike

我尝试在 Android 应用程序中为我的吉他制作一个调音器。为此,我使用了库AudioRecord.java,但在编译时出现错误:

07-03 13:48:49.041 2391-2426/? E/AudioRecord: AudioFlinger could not create record track, status: -1
07-03 13:48:49.044 2391-2426/? E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
07-03 13:48:49.044 2391-2426/? E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.

--------- beginning of crash
07-03 13:48:49.046 2391-2426/? E/AndroidRuntime: FATAL EXCEPTION: Thread-5
Process: com.example.gaetan.tuner, PID: 2391
java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.
at android.media.AudioRecord.startRecording(AudioRecord.java:976)
at com.example.gaetan.tuner.audio.CaptureThread.run(CaptureThread.java:34)

AudioRecord.java中我可以看到

import android.os.ServiceManager; cannot be resolved 

我可以做些什么来改变这种情况?

最佳答案

这个问题很可能与支持的采样率有关。以下代码将为您提供一个谓词,用于检查是否支持您所需的采样率。

        int sampleRate = 44100;
int bufferSize = AudioRecord.getMinBufferSize(44100, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT, AudioFormat.ENCODING_PCM_16BIT);

if (bufferSize > 0) {
//the sample rate is supported so create your AudioRecord
} else {
// sample size is not supported
}

有关支持多种采样率的更高级版本,请参阅给出的答案 here

关于java - android.media.AudioRecord;错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44887867/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com