我正在尝试录制用户的声音并在点击按钮时播放它但我得到的是“WARN/System.err(25236): java.io.IOException: Prepare failed.: status=0x1"
。”
(参见下面的“LogCat”)
我记录音频如下:
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(getApplicationContext().getFileStreamPath("audio_voicePrint").getAbsolutePath());
recorder.setOnErrorListener(this);
recorder.setOnInfoListener(this);
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
发布就像这样:
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
这就是我尝试播放的方式:
mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mp.setDataSource(getApplicationContext(), Uri.parse("file://"+getApplicationContext().getFileStreamPath("audio_voicePrint").getAbsolutePath()+".3gp"));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
使用Uri Uri.parse(getApplicationContext().getFileStreamPath("audio_voicePrint").getAbsolutePath())
和Uri.parse("file://"+getApplicationContext().getFileStreamPath("audio_voicePrint").getAbsolutePath()+".3gp")
时会出现同样的错误。
08-04 12:28:56.780: INFO/StagefrightPlayer(68): setDataSource('/data/data/com.abc.mobile/files/audio_voicePrint.3gp')
08-04 12:28:56.780: ERROR/MediaPlayer(25236): error (1, -2147483648)
08-04 12:28:56.780: WARN/System.err(25236): java.io.IOException: Prepare failed.: status=0x1
08-04 12:28:56.790: WARN/System.err(25236): at android.media.MediaPlayer.prepare(Native Method)
08-04 12:28:56.790: WARN/System.err(25236): at com.abc.mobile.Step4.onClick(Step4.java:228)
08-04 12:28:56.790: WARN/System.err(25236): at android.view.View.performClick(View.java:2485)
08-04 12:28:56.790: WARN/System.err(25236): at android.view.View$PerformClick.run(View.java:9080)
08-04 12:28:56.790: WARN/System.err(25236): at android.os.Handler.handleCallback(Handler.java:587)
08-04 12:28:56.790: WARN/System.err(25236): at android.os.Handler.dispatchMessage(Handler.java:92)
08-04 12:28:56.790: WARN/System.err(25236): at android.os.Looper.loop(Looper.java:130)
08-04 12:28:56.790: WARN/System.err(25236): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-04 12:28:56.790: WARN/System.err(25236): at java.lang.reflect.Method.invokeNative(Native Method)
08-04 12:28:56.790: WARN/System.err(25236): at java.lang.reflect.Method.invoke(Method.java:507)
08-04 12:28:56.800: WARN/System.err(25236): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-04 12:28:56.800: WARN/System.err(25236): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-04 12:28:56.800: WARN/System.err(25236): at dalvik.system.NativeStart.main(Native Method)
08-04 12:28:56.800: ERROR/MediaPlayer(25236): start called in state 0
08-04 12:28:56.800: ERROR/MediaPlayer(25236): error (-38, 0)
08-04 12:28:56.810: ERROR/MediaPlayer(25236): Error (-38,0)
根据this,错误-38是:
214 const PVMFStatus PVMFErrDrmClockError = (-38);
215 /*
216 DRM license store is corrupted
217 */
答案 0 :(得分:3)
使用此代码:
mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
FileInputStream fis = new FileInputStream(yourFilename);
mp.setDataSource(fis.getFD);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();