AudioRecord 遇到的问题
问题1:
AudioRecord: Could not get audio input for session xxx, record source xx, sample rate 16000, format ...
AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -22.
android.media.AudioRecord: Error code -20 when initializing native AudioRecord object
这个问题的愿意可以在整个系统日志中看到
ServiceManager: Permission failure: android.permission.CAPTURE_AUDIO_OUT from uid=xxxAudioPolicyIntefaceImpl: getInputForAttr() permission denied: capture not allowd
也就是这个是一个权限问题,解决方法:
方法1. 把此应用置为系统应用(android:sharedUserId=“android.uid.system”)
方法2. 在frameworks/base/core/java/android/content/PermissionChecker.java中 checkPermission 函数中直接允许你的包名有录音权限
public static int checkPermission(...) {if (packageName.equals("包名")) {return PERMISSION_GRANTED;}
}
问题2:
AudioPolicyManagerCustom: startInput(134) failed: other input 110 already started
AudioRecord: start() status -38
这个是由于在音频关闭前去录音了,需要在音频打开后录音。