gpt4 book ai didi

java - MediaRecorder 启动失败错误

转载 作者:行者123 更新时间:2023-11-29 23:57:00 26 4
gpt4 key购买 nike

我想录制通话语音,但我收到 MediaRecorder:start failed : -2147483648

这是我的通话记录代码块

   public void SesKayitBaslat(String number) {

Toast.makeText(context, "ANSWERED", Toast.LENGTH_LONG).show();

String out = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss").format(new Date());
File sampleDir = new File(Environment.getExternalStorageDirectory(), "/ASesKaydi");
if (!sampleDir.exists()) {
sampleDir.mkdirs();
}
String file_name = "Record";
try {
audiofile = File.createTempFile(file_name, ".amr", sampleDir);
} catch (IOException e) {
e.printStackTrace();
}
String path = Environment.getExternalStorageDirectory().getAbsolutePath();

recorder = new MediaRecorder();
//recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);

recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audiofile.getAbsolutePath());
try {
recorder.prepare();
} catch (IllegalStateException e) {
Log.e("Eror","1");
e.printStackTrace();
} catch (IOException e) {
Log.e("Eror","2");
e.printStackTrace();
}
if(!recordstarted)
{

recorder.start();
recordstarted = true;
}
Log.e("Kayit:", "Başladı");

}

我的错误是什么?谁能帮我 ?我试过 MediaRecorder.AudioSource.VOICE_CALL 和 MediaRecorder.AudioSource.VOICE_COMMUNICATION当我使用 Voice_Communication 类型时,我听不到来电者的声音。

最佳答案

代码 2147483648 指的是 MEDIA_ERROR_SYSTEM(低级系统错误)。

基于文档:

A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent). Once your code returns from this function, the system considers the object to be finished and no longer active.

换句话说,您期望存在的 MediaRecorder 实例实际上可能不再存在,因为您位于与创建 MediaRecorder 的实例不同的 BroadcastReceiver 实例中。在 BroadcastReceiver 中执行此任务不是一个好主意,因为它只会执行 10 秒,之后系统可以声明应用程序没有响应。

一个解决方案是将此代码执行到 Service

关于java - MediaRecorder 启动失败错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50257024/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com