我使用MediaRecoder錄製聲音,但錄製完成後無法播放。我嘗試過使用Google Play音樂,ES Media Player,甚至將它上傳到電腦,並嘗試用Winamp打開它。沒有什麼玩的!無法播放使用MediaRecorder錄製的文件
//AUDIO RECORDER
recorder = new MediaRecorder();
recorder.reset();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
externalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
externalOutputPath = externalStoragePath + File.separator + "/Android/data/com.whizzappseasyvoicenotepad/test.mp3";
recorder.setOutputFile(externalOutputPath);
}
else
{
storagePath = Environment.getDataDirectory().getAbsolutePath();
recorder.setOutputFile(storagePath + "/Android/data/com.whizzappseasyvoicenotepad/test.mp3");
}
即使試圖用按鈕點擊打開它的應用程序中:
public void testPlay (View v) throws IllegalArgumentException, SecurityException, IllegalStateException, IOException{
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(externalOutputPath);
mediaPlayer.prepare();
mediaPlayer.start();
}
但是,崩潰的應用程序。但這不是主要問題,主要問題是我無法播放該文件。編碼有什麼問題嗎?
我也試圖將它從.mp3改爲.3gp,但它不起作用。然後我也嘗試刪除.mp3和.3gp,只留下'測試'作爲名稱,然後它甚至不會將其識別爲音頻文件。
哦,如果有人想在logcat中,當應用程序崩潰:
07-31 16:51:43.953: E/AndroidRuntime(26918): java.lang.IllegalStateException: Could not execute method of the activity
07-31 16:51:43.953: E/AndroidRuntime(26918): Caused by: java.lang.reflect.InvocationTargetException
07-31 16:51:43.953: E/AndroidRuntime(26918): Caused by: java.io.IOException: setDataSourceFD failed.: status=0x80000000
但同樣,應用程序崩潰是不是此刻的問題。首先,我想解決爲什麼音頻文件無法播放的問題。但如果你有任何想法,爲什麼它崩潰,我也很感激它!
這爲我做。我意識到我錯過了MediaRecorder實例上的release()調用。謝謝! – rpm