2015-06-24 78 views
0

我添加了「pause.Timer = true;」在媒體播放器編碼和「pauseTimer = false;」之前在媒體播放器編碼後,但應用程序顯示音頻正在讀取問題時定時器仍在播放。問題是簡單的問題和問題。我的代碼錯了嗎?正在播放音頻時的暫停計時器

這些是我的代碼;

}。開始();}

private int getScore(){ 
     String scoreStr = scoreTxt.getText().toString(); 
     return Integer.parseInt(scoreStr.substring(scoreStr.lastIndexOf(" ")+1)); 
    } 

    private void chooseQuestion(){ 
     answerTxt.setText("= ?"); 
     QnNum = random.nextInt(QnsList.length); 

    final int DELAY_MS = 1000; 


     question.setText("Qn "+(questionNumber)); 

     pauseTimer = true; 

     qn = MediaPlayer.create(this, QnsList[QnNum]); 
     qn.setOnCompletionListener(new OnCompletionListener() { 
     @Override 
     public void onCompletion(MediaPlayer qn) { 
      qn.stop(); 
      qn.reset(); 
      qn.release(); 
      qn = null; 

     } 
    }); 

     if (leftTimeInMillisecondsGlobal == 0) { 
      if (countDownTimer != null) { 
       countDownTimer.cancel(); 
      } 
      setTimer(originalTimerTimeInMilliSeconds); 
     } else { 
      if (countDownTimer != null) { 
       countDownTimer.cancel(); 
      } 
      setTimer(leftTimeInMillisecondsGlobal); 
     } 

     pauseTimer = false; 

     startTimer(); 

     qn.start();} 

回答

0

雖然我不知道你是如何工作的定時器,但暗示該解決方案。

Move pauseTimer = false;在MediaPlayer的onCompletionListener中。

例:

private void chooseQuestion(){ 
    answerTxt.setText("= ?"); 
    QnNum = random.nextInt(QnsList.length); 

final int DELAY_MS = 1000; 


    question.setText("Qn "+(questionNumber)); 

    pauseTimer = true; 

    qn = MediaPlayer.create(this, QnsList[QnNum]); 
    qn.setOnCompletionListener(new OnCompletionListener() { 
    @Override 
    public void onCompletion(MediaPlayer qn) { 
     qn.stop(); 
     qn.reset(); 
     qn.release(); 
     qn = null; 
     pauseTimer = false; 


    } 
}); 

    if (leftTimeInMillisecondsGlobal == 0) { 
     if (countDownTimer != null) { 
      countDownTimer.cancel(); 
     } 
     setTimer(originalTimerTimeInMilliSeconds); 
    } else { 
     if (countDownTimer != null) { 
      countDownTimer.cancel(); 
     } 
     setTimer(leftTimeInMillisecondsGlobal); 
    } 


    startTimer(); 

    qn.start(); 

}

+0

當音頻跟它的問題款項我試着出,但是當我出場比賽,計時器仍在運行的「pauseTimer =假」題。我是否缺少任何其他代碼或什麼? – kjy

相關問題