播放我刚刚使用 MediaRecord 类录制的内容时遇到问题。
代码:
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();
}
我确实抓住了这个例外:java.io.IOException: prepare failed
有什么想法可以在这里发生吗?我猜这个setDataSource
电话是不正确的。
编辑-来自stackTrace:
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)