在使用Twilio拨打电话的过程中,我试图通过麦克风从Android手机录制音频。由于有多个I/org.webrtc.Logging
条目,因此Twilio似乎使用了webRTC。我已经缩小了一些与存储,权限,setAudioEncoder()
/ setOutputFormat()
呼叫相关的问题,并且此SO Q / A表明错误与使用手机麦克风的另一项服务有关。
MediaRecorder start failed: -38
更是如此,是否有可能与webRTC并行捕获音频,或者是否有某种方法可以挂接到音频流中?
我尝试了几种配置,但是主要是我尝试操纵顺序,类型和设置,这些都给了我不同程度的成功。据我所知,下面的代码。似乎暗示我不能使用麦克风进行其他服务。
public void onConnected(Call call) {
setAudioFocus(true);
recorder = new MediaRecorder();
Log.d(TAG, "created recorder");
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
Log.d(TAG, "set source");
recorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
Log.d(TAG, "set output");
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); // TODO: change format, codec
Log.d(TAG, "set codec");
fileName = getExternalCacheDir().getAbsolutePath();
fileName += "/audiorecordtest.aac";
recorder.setOutputFile(fileName);
Log.d(TAG, "set file");
try {
recorder.prepare();
} catch (IOException e) {
Log.e(TAG, "prepare() failed");
}
recorder.start();
Log.d(TAG, "Connected");
activeCall = call;
}
这是Logcat的输出...
2019-05-20 15:46:04.865 13078-13132/product I/org.webrtc.Logging: WebRtcAudioRecord: startRecording
2019-05-20 15:46:04.870 13078-13163/product I/org.webrtc.Logging: WebRtcAudioRecord: AudioRecordThread@[name=AudioRecordJavaThread, id=563]
2019-05-20 15:46:04.969 13078-13078/product D/CallActivity: created recorder
2019-05-20 15:46:04.972 13078-13078/product D/CallActivity: set source
2019-05-20 15:46:04.972 13078-13078/product D/CallActivity: set output
2019-05-20 15:46:04.973 13078-13078/product D/CallActivity: set codec
2019-05-20 15:46:04.975 13078-13078/product D/CallActivity: set file
2019-05-20 15:46:05.005 13078-13078/product E/MediaRecorder: start failed: -38
2019-05-20 15:46:05.005 13078-13078/product D/AndroidRuntime: Shutting down VM
2019-05-20 15:46:05.006 13078-13078/product E/AndroidRuntime: FATAL EXCEPTION: main
Process: product, PID: 13078
java.lang.IllegalStateException
at android.media.MediaRecorder.start(Native Method)
at product.CallActivity$2.onConnected(CallActivity.java:259)
at com.twilio.voice.Call$1$2.run(Call.java:532)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2019-05-20 15:46:05.011 13078-13078/product I/Process: Sending signal. PID: 13078 SIG: 9