I'm trying to record the users voice and play it back onClick of a button but I'm getting a "WARN/System.err(25236): java.io.IOException: Prepare failed.: status=0x1"
.
I record the audio like so:
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();
}
And release it like so:
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
This is how I attempt to play it back:
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();
I get the same error when using the Uri Uri.parse(getApplicationContext().getFileStreamPath("audio_voicePrint").getAbsolutePath())
and Uri.parse("file://"+getApplicationContext().getFileStreamPath("audio_voicePrint").getAbsolutePath()+".3gp")
.
LogCat:
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)
According to this, error -38 is:
214 const PVMFStatus PVMFErrDrmClockError = (-38);
215 /*
216 DRM license store is corrupted
217 */
use this code:
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();
精彩评论