2
- 我已經開發的應用程序,其中有4個聲音文件一起玩
- 乍一聽:下次按下按鈕
- - 第二聲音:
- 上一個按鈕按下
- 第三個soun d:
- 發揮項目的聲音
第四聲音:在項目多種聲音媒體播放器應用程序崩潰
- 劇(項目如何講)
工作一切良好,直到用戶快速回放和第四,文本到語音轉換e ngine崩潰與
的MediaPlayer:錯誤(-19,0)安卓
- 我試圖重啓媒體播放器,釋放和停止在一個和上一個按鈕,但還是聲音的項目的停止經過幾回和第四。
我做了什麼:
public class A extends Activity {
int imgArr[] = {R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d};
int soundsrc[] = {R.raw.a, R.raw.b, R.raw.c, R.raw.d};
String pro[] = new String[]{"a", "b", "c", "d"};
ImageView iView;
int count = 0;
TextToSpeech txtToSpeech1;
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_names);
stopService(new Intent(this, PlayMusic.class));
iView = (ImageView) findViewById(R.id.imageView5);
iView.setImageResource(R.drawable.befora);
txtToSpeech1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
txtToSpeech1.setLanguage(Locale.UK);
txtToSpeech1.speak(pro[count], TextToSpeech.QUEUE_FLUSH, null);
}
}
});
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
aSounds();
}
}, 1000);
}
@Override
public void onDestroy() {
// Don't forget to shutdown!
if (txtToSpeech1 != null) {
txtToSpeech1.stop();
txtToSpeech1.shutdown();
}
super.onDestroy();
}
public void onPause(){
if(txtToSpeech1 !=null){
txtToSpeech1.stop();
txtToSpeech1.shutdown();
}
super.onPause();
}
public void aSounds() {
mp = MediaPlayer.create(ANames.this, soundsrc[count]);
mp.start();
}
public void forwardd(View v) {
buttonSounds(R.raw.multimedia_button_click);
if (count < imgArr.length && count >= 0) {
count++;
if (count == imgArr.length)
count = 0;
iView.setImageResource(imgArr[count]);
if (txtToSpeech1.isSpeaking()) {
Log.i("Tag", "Stop speaking");
txtToSpeech1.stop();
}
txtToSpeech1.speak(pro[count], TextToSpeech.QUEUE_FLUSH, null);
// Execute some code after 2 seconds have passed
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
aSounds();
}
}, 1000);
}
}
public void backwardd(View v) {
buttonSounds(R.raw.multimedia_button_click);
if (count >= 0 && count < imgArr.length) {
count--;
if (count == -1) {
count = imgArr.length - 1;
}
iView.setImageResource(imgArr[count]);
txtToSpeech1.speak(pro[count], TextToSpeech.QUEUE_FLUSH, null);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
aSounds();
}
}, 1000);
}
}
public void onImageClick(View v) {
txtToSpeech1.speak(pro[count], TextToSpeech.QUEUE_FLUSH, null);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
aSounds();
}
}, 1000);
}
public void home(View v) {
buttonSounds(R.raw.multimedia_button_click);
Intent ii = new Intent(ANames.this, PlayMusic.class);
finish();
startService(ii);
}
public void buttonSounds(int src) {
mp = MediaPlayer.create(ANames.this, R.raw.multimedia_button_click);
mp.start();
}
}
- 試過幾乎所有的堆棧溢出的答案也是谷歌關於媒體播放器的工作 - 因爲非常非常非常長的
我一直在努力。
- 怎麼也停止,釋放,復位,啓動按鈕點擊媒體播放器,但沒有工作對我來說 ..
- 所以最後決定把問題在堆棧溢出的幫助
- 任何幫助是heartly歡迎和感謝提前