MediaRecorder 启动失败错误
MediaRecorder Start Failed Error
我想录制通话语音,但我收到 MediaRecorder:start 失败:-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
我想录制通话语音,但我收到 MediaRecorder:start 失败:-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