Android:使用 MediaRecorder 录制音频 - 文件无法播放
Android: recording audio using MediaRecorder - file doesnt play
我已经使用 MediaRecorder
直接从 Google 实现了示例代码
我还添加了一些属性并将文件类型设置为“.mp3”(我知道它不会创建真正的 mp3,但“.3gp”对我来说也没有意义,我录制的是音频而不是视频..)
现在我的问题是,如果我想播放文件,它什么也不做(0:00 秒)。我检查了文件的属性,它填满了存储 space。
附加:
无论如何,我想在录制时实现视觉反馈。 Horizon 似乎是唯一好看的库。但是使用 Horizon,您必须使用 Audiorecorder 的缓冲区来提供它,这对于 MediaRecoder 是不可能的。有谁知道一个漂亮的库,它可以可视化当前使用 MediaRecorder 录制的音频?
非常感谢
private void startRecording() {
if(this.mRecorder != null)
return;
String fileToWrite = this.ProjectDirPath + File.separator + GetToday() + this.fileTpye;
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setOutputFile(fileToWrite);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.HE_AAC);
mRecorder.setAudioSamplingRate(16000);
mRecorder.setAudioEncodingBitRate(44100);
mRecorder.setAudioChannels(1);
try {
mRecorder.prepare();
}catch (IOException e) {
Log.e("startRecording()", "prepare() failed");
}
initRecorder();
mRecorder.start();
isRecording = true;
}
private void stopRecording() {
if(this.mRecorder == null)
return;
else{
try{
mRecorder.stop();
mRecorder.release();
mRecorder = null;
isRecording = false;
this.updateListView();
} catch(Exception e){
mRecorder = null;
isRecording = false;
}
}
}
public static String GetToday(){
Date presentTime_Date = Calendar.getInstance().getTime();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return dateFormat.format(presentTime_Date);
}
权限在清单中和运行时设置。
我已经使用 MediaRecorder
直接从 Google 实现了示例代码我还添加了一些属性并将文件类型设置为“.mp3”(我知道它不会创建真正的 mp3,但“.3gp”对我来说也没有意义,我录制的是音频而不是视频..)
现在我的问题是,如果我想播放文件,它什么也不做(0:00 秒)。我检查了文件的属性,它填满了存储 space。
附加:
无论如何,我想在录制时实现视觉反馈。 Horizon 似乎是唯一好看的库。但是使用 Horizon,您必须使用 Audiorecorder 的缓冲区来提供它,这对于 MediaRecoder 是不可能的。有谁知道一个漂亮的库,它可以可视化当前使用 MediaRecorder 录制的音频?
非常感谢
private void startRecording() {
if(this.mRecorder != null)
return;
String fileToWrite = this.ProjectDirPath + File.separator + GetToday() + this.fileTpye;
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setOutputFile(fileToWrite);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.HE_AAC);
mRecorder.setAudioSamplingRate(16000);
mRecorder.setAudioEncodingBitRate(44100);
mRecorder.setAudioChannels(1);
try {
mRecorder.prepare();
}catch (IOException e) {
Log.e("startRecording()", "prepare() failed");
}
initRecorder();
mRecorder.start();
isRecording = true;
}
private void stopRecording() {
if(this.mRecorder == null)
return;
else{
try{
mRecorder.stop();
mRecorder.release();
mRecorder = null;
isRecording = false;
this.updateListView();
} catch(Exception e){
mRecorder = null;
isRecording = false;
}
}
}
public static String GetToday(){
Date presentTime_Date = Calendar.getInstance().getTime();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return dateFormat.format(presentTime_Date);
}
权限在清单中和运行时设置。