我试图在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
我可以做些什么来改变它?
答案 0 :(得分:0)
该问题可能与支持的采样率有关。以下代码将为您提供一个谓词,用于检查是否支持您所需的采样率。
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
的答案