1
遇到麻煩回放我剛剛用MediaRecord類錄製的內容。Android:使用MediaRecorder錄製後播放媒體文件
代碼:
try {
audioSample = File.createTempFile("sample", ".wav", PlayScreen.this.getCacheDir());
} catch (IOException e) {
Toast.makeText(PlayScreen.this, "ERROR: unable to create temp audio file!" + e.toString(), Toast.LENGTH_LONG).show();
return;
}
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audioSample.getAbsolutePath());
try {
recorder.prepare();
} catch (Exception e) {
Toast.makeText(PlayScreen.this, "RECORDER ERROR: " + e.toString(), Toast.LENGTH_LONG).show();
Log.e("PLAYSCREEN", e.toString());
return;
}
recorder.start();
這是錄音。我認爲這是工作,因爲我沒有趕上任何錯誤的;)
現在的播放代碼:
try {
mp.setDataSource(audioSample.getAbsolutePath());
mp.prepare();
mp.start();
} catch (Exception e) {
Toast.makeText(PlayScreen.this, "PLAYBACK TEST FAIL: " + e.toString(), Toast.LENGTH_LONG).show();
}
這exceptionb我趕上:java.io.IOException: prepare failed
任何想法可能會參加在這?我猜setDataSource
電話是不正確的。
編輯 - 從堆棧跟蹤:
01-08 12:35:35.609: W/System.err(24730): java.io.IOException: Prepare failed.: status=0xFFFFFFFC
01-08 12:35:35.609: W/System.err(24730): at android.media.MediaPlayer.prepare(Native Method)
01-08 12:35:35.609: W/System.err(24730): at com.jsx.audiotech.PlayScreen$1.onClick(PlayScreen.java:125)
01-08 12:35:35.609: W/System.err(24730): at android.view.View.performClick(View.java:2461)
01-08 12:35:35.609: W/System.err(24730): at android.view.View$PerformClick.run(View.java:8890)
01-08 12:35:35.609: W/System.err(24730): at android.os.Handler.handleCallback(Handler.java:587)
01-08 12:35:35.609: W/System.err(24730): at android.os.Handler.dispatchMessage(Handler.java:92)
01-08 12:35:35.609: W/System.err(24730): at android.os.Looper.loop(Looper.java:123)
01-08 12:35:35.609: W/System.err(24730): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-08 12:35:35.613: W/System.err(24730): at java.lang.reflect.Method.invokeNative(Native Method)
01-08 12:35:35.613: W/System.err(24730): at java.lang.reflect.Method.invoke(Method.java:521)
01-08 12:35:35.613: W/System.err(24730): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
01-08 12:35:35.613: W/System.err(24730): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-08 12:35:35.617: W/System.err(24730): at dalvik.system.NativeStart.main(Native Method)
你可以發佈更多的堆棧跟蹤,以便我們可以看到實際的錯誤?使用'e.printStackTrace()',而不是把它放在烤麪包上,它應該給你更多關於完全出錯的信息 –
用堆棧跟蹤更新了OP。 – JDS