0
你好,我已經創建了一個小的應用程序,我在錄製音頻。我的問題是,在下面的代碼中,我可以在特定的文件夾中創建一個文件,但是當我試圖播放這個音頻文件時,它說這個媒體文件不支持。 plz幫助在android中的媒體記錄器
public void startRecording() {
System.out.println("STart Recording");
if (recorder != null) {
recorder.release();
} else {
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setOutputFile(getFilePath());
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
recorder.release();
}
}
}
private void stopRecording() {
System.out.println("Stop Recording");
try {
if (null != recorder) {
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
}
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
private String getFilePath() {
File rsd = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
if (!rsd.isDirectory()) {
rsd.mkdir();
}
File dcim = new File(rsd + "/hello.mp3");
return dcim.getAbsolutePath();
}
你想聽的文件是MP3,你在刻錄的格式是MediaRecorder.OutputFormat.THREE_GPP,也許這就是原因... –
我認爲你需要添加一個庫...也許這會幫助你: http://stackoverflow.com/questions/3641920/how-to-encode-a-wav-to-a-mp3-on-a-android-device/ –
這裏是清單權限 <使用權限android:name =「android.permission.WRITE_EXTERNAL_STORAGE」/> –
Nik