我正在为Android拨打应用程序来收听电话。问题是初始化失败。
我的日志:
E/AudioRecord﹕ Could not get audio input for record source 3
E/AudioRecord-JNI﹕ Error creating AudioRecord instance: initialization check failed.
E/android.media.AudioRecord﹕ Error code -20 when initializing native AudioRecord object.
我的代码:
public AudioRecord recorder;
private int sampleRate = 16000;
private int channelConfig = AudioFormat.CHANNEL_IN_MONO;
private int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
int minBufSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
recorder = new AudioRecord(MediaRecorder.AudioSource.VOICE_DOWNLINK, sampleRate, channelConfig, audioFormat, minBufSize * 10);
recorder.startRecording();
编辑: 我只想要DOWNLINK
答案 0 :(得分:0)
你应该使用AudioRecord的MediaRecorder instade, 听到是录制音频的一个例子并保存在你的sdCard中。
MediaRecorder myAudioRecorder;
outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/recording.3gp";
myAudioRecorder=new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);
您可以使用以下代码
开始在按钮点击事件上录制 try {
myAudioRecorder.prepare();
myAudioRecorder.start();
}
catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}