我正在使用下面的代码来获取设备的有效采样率,但它总是audioRecorder.getState()
为我的三星 Galaxy Tab 1 OS 版本 2.3.6 发送 0,但它对三星 Galaxy S2 很好。
我总是得到 Galaxy Tab 的手段desiredRate = -1;
public static void getValidSampleRates() {
int desiredRate = 0;
for (int rate : new int[] {44100, 8000, 11025, 16000, 22050}) { // add the rates you wish to check against
int bufferSize = AudioRecord.getMinBufferSize(rate, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT, AudioFormat.ENCODING_PCM_16BIT);
if (bufferSize > 0) {
// buffer size is valid, Sample rate supported
AudioRecord audioRecorder = new AudioRecord(AudioSource.MIC, rate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, 21168);
if (audioRecorder.getState() != AudioRecord.STATE_INITIALIZED)
desiredRate = -1;
else
desiredRate = rate;
}
}
}
我在Android 清单文件中添加了以下权限
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<application
请帮忙