英文:
Outgoing call recording audio file has no sound
问题
记录完一次外拨电话后,我尝试播放录制的文件,以确保通话录音按预期工作(我是使用 'MediaPlayer' 进行播放的),但是没有声音。所以我试图访问手机上的实际文件(简单地将手机连接到计算机并访问其文件)。当我播放录音时,它的长度是正确的,但仍然没有声音。
我漏掉了什么?
以下是我录制电话通话的方式:
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
// recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
File callAudioFile = null;
try {
File downloadsDir = context.getApplicationContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
callAudioFile = File.createTempFile("deTuCelRecord", ".amr", downloadsDir);
} catch (IOException e) {
e.printStackTrace();
}
assert callAudioFile != null;
audioFilePath = callAudioFile.getAbsolutePath();
recorder.setOutputFile(audioFilePath);
try {
recorder.setOnErrorListener(new MediaRecorder.OnErrorListener() {
@Override
public void onError(MediaRecorder mr, int what, int extra) {
Log.e("MediaRecorder", "MediaRecorder error " + what + " " + extra);
}
});
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
recorder.start();
以下是结束通话录音的代码:
recorder.stop();
recorder.release();
以下是播放音频文件的方式:
MediaPlayer mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(audioFilePath);
mPlayer.prepare();
Toast.makeText(getApplicationContext(), "PLAYING AUDIO", Toast.LENGTH_LONG).show();
mPlayer.start();
Log.d("PLAY_AUDIO", "Started playing audio");
} catch (IOException e) {
Log.e("PLAY_AUDIO", "Failed to play audio");
}
英文:
After recording an outgoing phone call, I am trying to play the recorded file - to make sure the call recording worked as expected (I am doing it using 'MediaPlayer'), but there is no sound.
So I tried to access the actual file on the phone (simply attached the phone to the computer and accessed it's files). When I played it the recording it was in the right length but again no sound.
What am I missing?
This is how I record the phone call:
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
// recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
File callAudioFile = null;
try {
File downloadsDir = context.getApplicationContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
callAudioFile = File.createTempFile("deTuCelRecord", ".amr", downloadsDir);
} catch (IOException e) {
e.printStackTrace();
}
assert callAudioFile != null;
audioFilePath = callAudioFile.getAbsolutePath();
recorder.setOutputFile(audioFilePath);
try {
recorder.setOnErrorListener(new MediaRecorder.OnErrorListener() {
@Override
public void onError(MediaRecorder mr, int what, int extra) {
Log.e("MediaRecorder", "MediaRecorder error " + what + " " + extra);
}
});
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
recorder.start();
This is the code which ends the call recording:
recorder.stop();
recorder.release();
This is how I play the audio file:
MediaPlayer mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(audioFilePath);
mPlayer.prepare();
Toast.makeText(getApplicationContext(), "PLAYING AUDIO", Toast.LENGTH_LONG).show();
mPlayer.start();
Log.d("PLAY_AUDIO", "Started playing audio");
} catch (IOException e) {
Log.e("PLAY_AUDIO", "Failed to play audio");
}
答案1
得分: 0
请在您的测试手机上检查此辅助功能服务。
如果您正在尝试在Android Q上录制通话,请参考此链接。
您可以尝试使用以下代码:
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
需要Manifest.permission.CAPTURE_AUDIO_OUTPUT
权限。
请查看声音源文档以了解VOICE_CALL和VOICE_COMMUNICATION之间的区别。
英文:
Please check this Accessibilty Service in your testing phone.
If you are trying to record call on Android Q.
Please refer this link
You can try
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
It need Manifest.permission.CAPTURE_AUDIO_OUTPUT
permission.
Please check AudioSource Source documentation for difference between VOICE_CALL and VOICE_COMMUNICATION
答案2
得分: 0
问题是Android版本-从Android 10开始,它不允许我录制通话,但在Android 9上可以。
英文:
The issue was the android version - from android 10 it didn't allow me to record the call but on android 9 it did.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论