以下是我用来通过 MIC 以 .opus 格式录制音频的代码。我总是收到错误 MediaRecorder:启动失败:-38。但是,如果将输出格式和音频编码器更改为任何其他格式,例如带有 AAC 或 AMR 的 THREE_GPP、MPEG_4,这将正常工作。由于我需要 opus 文件类型,我不能使用任何其他音频格式。由于 android 在 opus over (Android 5.0+) 设备上有官方支持,这应该可以工作。如果我在这里做错了什么,请纠正我。
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.WEBM);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.VORBIS);
mRecorder.setOutputFile(fileName);
mRecorder.prepare();
mRecorder.start();