gpt4 book ai didi

android - 录制 + 播放问题(MediaRecorder + MediaPlayer)

转载 作者:太空狗 更新时间:2023-10-29 12:55:50 33 4
gpt4 key购买 nike

我正在尝试录制用户的声音并在单击按钮时播放它,但我收到“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 */

最佳答案

使用这段代码:

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();

关于android - 录制 + 播放问题(MediaRecorder + MediaPlayer),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6940936/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com