2
我想在android的通話記錄。我有以下代碼,當我使用 MediaRecorder.AudioSource.VOICE_DOWNLINK | MediaRecorder.AudioSource.VOICE_UPLINK正在錄製通話,但播放時無法理解。如果使用相同的代碼AudioSouce.MIC
然後錄製的文件是可以理解的。 這裏是我的代碼Android語音通話錄音問題....不能正常工作與audiosource.voicecall
package com.example.callrecoder;
import java.io.File;
import java.io.IOException;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button record_call = (Button)this.findViewById(R.id.record);
final Button stop_recorder = (Button)this.findViewById(R.id.stop);
final MediaRecorder _recorder = new MediaRecorder();
record_call.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
//MediaRecorder _recorder = new MediaRecorder();
try {
String state = android.os.Environment.getExternalStorageState();
/* if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
throw new IOException("SD Card is not mounted. It is " + state
+ ".");
}
// make sure the directory we plan to store the recording in exists
File directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/sam.wav").getParentFile();
if (!directory.exists() && !directory.mkdirs()) {
throw new IOException("Path to file could not be created.");
}*/
//_recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
_recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK | MediaRecorder.AudioSource.VOICE_UPLINK);
_recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
//_recorder.setOutputFile(Environment.getExternalStorageDirectory().getAbsolutePath()
// + "/test.wav");
_recorder.setOutputFile("/sdcard/sample.3GPP");
_recorder.prepare();
_recorder.start();
} catch (Exception e) {
e.printStackTrace();
}
}
});
stop_recorder.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try
{
_recorder.stop();
_recorder.reset();
_recorder.release();
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
//_recorder = null;
}
});
}
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}
我想記錄與AudioSource.downlink和上行鏈路的呼叫。 PLZ幫我解決了這個問題。我在Samsang Galaxay Gio手機上測試它。
你說的 「不理解」 是什麼意思?它以錯誤的速度播放?或者聽起來像隨機垃圾?當您錄製語音電話時,您很可能會獲得AMR編碼的數據,因此您使用的播放器可能存在AMR音頻問題?順便說一句,你應該使用VOICE_CALL,你想要上行鏈路和下行鏈路(儘管不是所有的設備都支持這一點)。 VOICE_UPLINK | VOICE_DOWNLINK不等於VOICE_CALL,因爲這些不是位掩碼。 – Michael
AMR編碼數據意味着什麼? –
我的意思是用[AMR編解碼器]編碼的數據(http://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec) – Michael