我正在学习如何使用http://developer.android.com/guide/topics/media/audio-capture.html#example录制音频
一切正常,但我想切换:
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += "/audiorecordtest.3gp";
至
mFileName = getFilesDir().getAbsolutePath();
mFileName += "/audiorecordtest.3gp";
但我得到这个错误
08-19 15:51:44.212: E/MediaPlayer(6654): error (1, -2147483648)
08-19 15:51:44.212: E/AudioRecordTest(6654): prepare() failed
我试图记录我的新代码(以确保我使用的是有效路径)。
笔记:
这适用于我的三星 Galaxy,但不适用于我的 Nexus One。我希望它适用于 2.x、3.x 和 4.x
更新: 我在 startRecording() 中添加了一个日志:
mRecorder.setOutputFile(mFileName);
Log.e("LOG", mFileName);
该日志的输出是:
08-22 12:28:40.112: E/LOG(9666): /data/data/com.example.testrecorder/files/audiorecordtest.3gp
尝试记录异常:
private void startPlaying() {
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(mFileName);
mPlayer.prepare();
mPlayer.start();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed", e);
}
}
08-22 13:08:03.158: E/MediaPlayer(10093): error (1, -2147483648)
08-22 13:08:03.168: E/AudioRecordTest(10093): prepare() failed
08-22 13:08:03.168: E/AudioRecordTest(10093): java.io.IOException: Prepare failed.: status=0x1
08-22 13:08:03.168: E/AudioRecordTest(10093): at android.media.MediaPlayer.prepare(Native Method)
08-22 13:08:03.168: E/AudioRecordTest(10093): at com.example.testrecorder.MainActivity.startPlaying(MainActivity.java:51)
08-22 13:08:03.168: E/AudioRecordTest(10093): at com.example.testrecorder.MainActivity.onPlay(MainActivity.java:41)
08-22 13:08:03.168: E/AudioRecordTest(10093): at com.example.testrecorder.MainActivity.access$1(MainActivity.java:39)
08-22 13:08:03.168: E/AudioRecordTest(10093): at com.example.testrecorder.MainActivity$PlayButton$1.onClick(MainActivity.java:113)
08-22 13:08:03.168: E/AudioRecordTest(10093): at android.view.View.performClick(View.java:2532)
08-22 13:08:03.168: E/AudioRecordTest(10093): at android.view.View$PerformClick.run(View.java:9308)
08-22 13:08:03.168: E/AudioRecordTest(10093): at android.os.Handler.handleCallback(Handler.java:587)
08-22 13:08:03.168: E/AudioRecordTest(10093): at android.os.Handler.dispatchMessage(Handler.java:92)
08-22 13:08:03.168: E/AudioRecordTest(10093): at android.os.Looper.loop(Looper.java:150)
08-22 13:08:03.168: E/AudioRecordTest(10093): at android.app.ActivityThread.main(ActivityThread.java:4333)
08-22 13:08:03.168: E/AudioRecordTest(10093): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 13:08:03.168: E/AudioRecordTest(10093): at java.lang.reflect.Method.invoke(Method.java:507)
08-22 13:08:03.168: E/AudioRecordTest(10093): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-22 13:08:03.168: E/AudioRecordTest(10093): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-22 13:08:03.168: E/AudioRecordTest(10093): at dalvik.system.NativeStart.main(Native Method)