2012-01-19 11 views
2

私は、サウンドとともに、ジャワ語の翻訳をしようとしています。翻訳結果は正常に表示されますが、音は出ません。例外をスローします。Android MediaPlayerの準備ができません

Java.io.IOException: Prepare failed: status=0x1 
at android.media.MediaPlayer.prepare(Native Method) 
at com.cinta.jawa.JawaSearchActivity.playAudio(JawaSearchActivity.java:51) 
at com.cinta.jawa.JawaSearchActivity$1.onClick(JawaSearchActivity.java:178) 
at android.view.View.performClick(View.java:2408) 
at android.view.View$PerformClick.run(View.java:8816) 
at android.os.Handler.handleCallback(Handler.java:587) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:123) 
at android.app.ActivityThread.main(ActivityThread.java:4627) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:521) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
at dalvik.system.NativeStart.main(Native Method) 

それは私がライン52および179で間違って得たことを言いますが、私はそれが間違って作るものは考えています。誰か助けてくれますか?

package com.cinta.jawa; import java.io.IOException; import java.util.ArrayList; import org.xmlpull.v1.XmlPullParserException; import android.app.Activity; import android.content.res.XmlResourceParser; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class JawaSearchActivity extends Activity { private EditText etSearch; private TextView tvResult; Jawa jawa = new Jawa(this); boolean booSearch = false; public static MediaPlayer myplayer = new MediaPlayer(); public static ArrayList<Uri> pathlist = new ArrayList<Uri>(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search); etSearch = (EditText) findViewById(R.id.editTextSearch); tvResult = (TextView) findViewById(R.id.textViewResult); Button btnSearch = (Button) findViewById(R.id.button_search); btnSearch.setOnClickListener(onClickListener); } public void playAudio() { try { if (myplayer.isPlaying()) { myplayer.stop(); myplayer.release(); } if (pathlist.size() >= 1) { for (int i = 0; i< pathlist.size();i++){ Uri path = pathlist.get(i); myplayer.setDataSource(this, path); myplayer.prepare(); /*this is the error line*/ myplayer.start(); } } } catch (Exception e) { e.printStackTrace(); } myplayer.setLooping(true); } private String[] getWord(XmlResourceParser words, String strWord) throws XmlPullParserException, IOException { int eventType = -1; String[] strReturn = new String[2]; while (eventType != XmlResourceParser.END_DOCUMENT) { if (eventType == XmlResourceParser.START_TAG) { String strName = words.getName(); if (strName.equals("word")) { String wordValue = words.getAttributeValue(null, "key"); if (wordValue.equalsIgnoreCase(strWord)) { strReturn[0] = words.getAttributeValue(null, "file"); strReturn[1] = words.getAttributeValue(null, "translate"); return strReturn; } } } eventType = words.next(); } return strReturn; } OnClickListener onClickListener = new OnClickListener() { public void onClick(View v) { XmlResourceParser jawaDictionary = getResources() .getXml(R.xml.jawa); String strWord[] = new String[2]; String[] strNumb = null; int intstrNumb = 0; String angkaBo = null; System.out.println("AWAL NIHH??" + angkaBo); Long angka = null; boolean booFind = false; StringBuilder strbTranslate = new StringBuilder(); myplayer.reset(); myplayer.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer arg0) { for (int i = 0; i< pathlist.size();i++){ pathlist.remove(i); if (pathlist.size() >= 1) { myplayer.reset(); playAudio(); } } } }); String strWords = etSearch.getText().toString().trim(); String[] astrWord = strWords.split(" "); int intCountWords = astrWord.length; for (int i = 0; i < intCountWords; i++) { try { String perWord = astrWord[i].trim(); int perWordL = perWord.length(); for (int x = 0; x < perWordL; x++) { if (Character.isDigit(perWord.charAt(x))) { angka = Long.parseLong(perWord); } } strWord = getWord(jawaDictionary, astrWord[i].trim()); System.out.println("STRWORD NYE APAAN??" + strWord[0]); jawaDictionary.close(); jawaDictionary = getResources().getXml(R.xml.jawa); if (strWord[0] != null) { System.out.println("MASUK SINI GA SIHHHHHH??"); strbTranslate.append(strWord[1]); strbTranslate.append(" "); System.out.println("COBA DILIAT " + strbTranslate); System.out.println("KALOYANG INI?? " + pathlist); tvResult.setText(strbTranslate); booSearch = true; } else { System.out.println("MASUK MANA DONK??"); if (angka != null) { angkaBo = NumberScanActivity.convert(angka); System.out.println("COBA LIAT INI MUNCUL GAKK??" + angkaBo); String angkaNih = angkaBo.trim(); strNumb = angkaNih.split(" "); System.out.println("HOHOHEHEHEHK??" + angkaNih); System.out.println("BLUKUTUKKK??" + strNumb); intstrNumb = strNumb.length; for (int y = 0; y < intstrNumb; y++) { System.out .println("MASUK SINI KAGA?? HAYOOOOOO " + strNumb[y]); strbTranslate.append(strNumb[y]); strbTranslate.append(" "); } tvResult.setText(strbTranslate); booSearch = true; } } } catch (Exception e) { } } String fullText = strbTranslate.toString(); pathlist = SyllableScanActivity.convertSentenceToSyl(fullText); System.out.println("COBA LIAT ISI PATHLIS APAAN>>>>>> "+pathlist); if (!myplayer.isPlaying()) { playAudio(); /*this is the error line*/ } if (booFind == false) { if (booSearch == false) tvResult.setText("Sorry, No Result"); } } }; }

答えて

0

このlinkこれはあなたの問題を解決するのに役立ちます参照してください:ここ はコードです。

私のプロジェクトでこのコードを使用してオーディオファイルを再生しています。私はmediaPlayer.prepair()を使用していません。

bGSound = MediaPlayer.create(MusicPlay.this,R.drawable.music_ground); 
      float bGLeftVol = (float) (bGSoundVolume.getProgress()/100.0); 
      float bGRightVol = (float) (bGSoundVolume.getProgress()/100.0); 
      bGSound.setLooping(true); 
      bGSound.setVolume(bGLeftVol, bGRightVol); 
      bGSound.start(); 
+0

わかりました...このヘルプのあなたかどうかを確認し、私はそれをしようとします。とにかく、Deepak、そのbGSoundの種類は何ですか? – Cintz

+0

ありがとう – Cintz

+0

これはMediaPlayerクラスのオブジェクトです。 – Deepak

関連する問題