0

私はあなたがここで私を助けてくれることを本当に望んでいます。以下は、2つのカウントダウンタイマーを並べて正常に実行するコードのセクションです...カウントダウンが終了したときに短いmp3ファイルを再生するだけです....私はさまざまなコードを試しましたが、何かをうまく機能させるのに苦労しています...すぐに勝つといいでしょう。

したがって、2つのタイマーを切り上げるには、それぞれが終了時にサウンドを再生する必要があります。

//Declare Start/Stop button
Button btnstart = (Button)findViewById(R.id.btnstart);
Button Button1 = (Button)findViewById(R.id.Button01);

final TextView mCounter1TextField=(TextView)findViewById(R.id.counter1);
final TextView mCounter2TextField=(TextView)findViewById(R.id.counter2);

//Counter 1
final CountDownTimer Counter1 = new CountDownTimer(9000000 , 1000) {
public void onTick(long millisUntilFinished) {
    mCounter1TextField.setText(" " + formatTime(millisUntilFinished));
}

public void onFinish() {
    start();
}

};

//Counter 2
final CountDownTimer counter2 = new CountDownTimer(9000000 , 1000) {
public void onTick(long millisUntilFinished) {
  mCounter2TextField.setText(" " + formatTime(millisUntilFinished));

}

public void onFinish() {
  start();
}


};

//Start Button1
btnstart.setOnClickListener(new OnClickListener() {
 public void onClick(View v) {
  Counter1.start();

   }
});

//Start Button2
 Button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
 counter2.start();

前もって感謝します

DJ

4

1 に答える 1

2

サウンドを再生するために呼び出す関数start()だと思いますよね?

したがって、の定義内にstart()次のコードを入れます。

MediaPlayer mp = MediaPlayer.create(getBaseContext(), sound); //replace 'sound' by your music/sound
mp.start();

お役に立てれば!

編集: 超明確にしようとしています:)

あなたのコードのどこかに、それは書かれています:

public void onFinish() {
    start();
}

このメソッド/関数は、カウンターが終了したときに呼び出されます。この関数の中には「start()」と書かれています

これが何をするのかわかりませんstart()

どちらの場合も、それを保持し(エラーが発生しない場合)、その後に2つのメソッド内start()に追加することをお勧めします。playSound()onFinish()

次に、この関数のOUTSIDEに次のように記述します。

public void playSound() {

MediaPlayer mp = MediaPlayer.create(getBaseContext(), sound); //replace 'sound' by your    music/sound
mp.start();

}
于 2012-02-12T10:29:06.890 に答える