请帮助我解决此错误,我从过去 5 天开始尝试此问题,但无法解决。
由于 android 中的“文本讲话”没有暂停状态,我正在尝试使用 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();
}
}
}
}