gpt4 book ai didi

java.io.IOException :prepared failed:status=0x1 异常

转载 作者:行者123 更新时间:2023-11-30 04:07:18 28 4
gpt4 key购买 nike

请帮我解决这个错误,我在过去 5 天一直在尝试这个问题,但无法解决。

由于android中的“Text to speach”没有暂停状态,我正在尝试用mediaplayer来暂停和播放。

将文本字符串转换为 .3gp 格式并存储在 sdcard 中,直到这里它工作正常,但我在 mediaPlayer 中遇到问题,它抛出以下错误

07-10 09:12:12.279: D/(13589): temper destination file/mnt/sdcard/tmpaudio.3gp
07-10 09:12:12.279: I/TextToSpeech.java - synthesizeToFile(13589): synthesizeToFile text of length 256
07-10 09:12:12.479: D/MediaPlayer(13589): setDataSource(tmpaudio.3gp)
07-10 09:12:12.489: E/MediaPlayer(13589): error (1, -2147483648)
07-10 09:12:12.489: W/System.err(13589): java.io.IOException: Prepare failed.: status=0x1
07-10 09:12:12.489: W/System.err(13589): at android.media.MediaPlayer.prepare(Native Method)
07-10 09:12:12.489: W/System.err(13589): at net.sf.andpdf.pdfviewer.PdfViewerActivity$GraphView$2.onClick(PdfViewerActivity.java:651)
07-10 09:12:12.489: W/System.err(13589): at android.view.View.performClick(View.java:2485)
07-10 09:12:12.489: W/System.err(13589): at android.view.View$PerformClick.run(View.java:9080)
07-10 09:12:12.489: W/System.err(13589): at android.os.Handler.handleCallback(Handler.java:587)
07-10 09:12:12.489: W/System.err(13589): at android.os.Handler.dispatchMessage(Handler.java:92)
07-10 09:12:12.489: W/System.err(13589): at android.os.Looper.loop(Looper.java:130)
07-10 09:12:12.489: W/System.err(13589): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-10 09:12:12.489: W/System.err(13589): at java.lang.reflect.Method.invokeNative(Native Method)
07-10 09:12:12.489: W/System.err(13589): at java.lang.reflect.Method.invoke(Method.java:507)
07-10 09:12:12.489: W/System.err(13589): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
07-10 09:12:12.489: W/System.err(13589): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
07-10 09:12:12.489: W/System.err(13589): at dalvik.system.NativeStart.main(Native Method)
07-10 09:12:12.489: D/MediaPlayer(13589): start state 0
07-10 09:12:12.489: E/MediaPlayer(13589): start called in state 0
07-10 09:12:12.489: E/MediaPlayer(13589): error (-38, 0)
07-10 09:12:12.529: E/MediaPlayer(13589): Error (-38, 0)

代码:

public void onClick(View v) {                   
mediaPlayer = new MediaPlayer();
if (mBtplay.getText().equals(getString(R.string.play_str))) {
PdfReader reader = null;
try {
reader = new PdfReader(pdffilename);
} catch (IOException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
int num = mPdfPage.getPageNumber();
String str = null;
try {
str = PdfTextExtractor.getTextFromPage(
reader, num);
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}

HashMap<String, String> myHashRender = new HashMap<String, String>();
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, str);

File appTmpPath = Environment.getExternalStorageDirectory();
System.out.println(""
+ appTmpPath.getAbsolutePath());
appTmpPath.mkdirs();
String tempFilename = "tmpaudio.3gp";

final String tempDestFile = appTmpPath
.getAbsolutePath() + "/" + tempFilename;
Log.d("","temper destination file"+tempDestFile);
mTts.synthesizeToFile(str, myHashRender,
tempDestFile);
try {
mediaPlayer.setDataSource(tempDestFile);
mediaPlayer.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try{
mediaPlayer.start();
}catch(Exception e){
System.out.println(""+e);

}
} else {
try {
Log.d("", "pause");

mBtplay.setText(getString(R.string.pause_str));
mediaPlayer.pause();
} catch (Exception pa) {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
}

}

}

}

最佳答案

我有一些建议给你。按给定顺序一一尝试。

1) 播放前检查您要播放的文件是否存在,路径是否正确。

2) 尝试不同的音频格式,例如 mp3。

3) 使用文件描述符而不是文件路径,即

FileInputStream fis = new FileInputStream(pathoffiletobeplayed);
mediaPlayer.setDataSource(fis.getFD());

4) 在setDataSource()之前调用reset()

1 是强制性的。如果不成功,请尝试 2​​-3-4 的所有组合。

关于java.io.IOException :prepared failed:status=0x1 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11406365/

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