玩倒计时报警 [英] Countdown playing Alarm

查看:125
本文介绍了玩倒计时报警的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的希望你能帮助我在这里。下面是我的code的一节,成功地运行着两个并排倒数计时器边......所有我想要做的就是玩的时候,倒计时结束后很短的MP3文件....我已经尝试了很多不同的位code,但我在努力做什么工作......一个快速取胜将是一件好事。

I really hope you can help me here. Below is a section of my code that successfully runs two count down timers side by side...all I want to do is play a short mp3 file when count down has finished....I have tried many different bits of code but I am struggling to make anything work...an quick wins would be good..

于是围捕两个定时器每个人都需要完成时播放的声音..

So to round up two timers each need to play sound when finished..

//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

推荐答案

我假设开始()是你调用播放声音,右边的功能?

I assume start() is the function you call to play the sound, right ?

所以的定义中的start(),把下面的code:

so inside the definition of start(), put the following code :

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

希望这有助于!

编辑: 想成为超清晰:)

在某处,code,它写的是:

Somewhere in your code, it is written :

public void onFinish() {
    start();
}

当计数器完成这个方法/函数被调用。
在这个函数中它被写为开始()

This method/function is called when the counter finishes. Inside this function it is written 'start()'

我不知道这是什么开始()一样。

I don't know what this start() does.

在这两种情况下,我建议你把它(如果它不产生错误),并在开始()添加 playSound ()两个 onFinish()方法内。

In both cases, I suggest you keep it (if it doesn't create an error), and after start(), add playSound() inside the two onFinish() methods.

然后写这个功能之外,以下内容:

and then write OUTSIDE of this function, the following:

public void playSound() {

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

}

这篇关于玩倒计时报警的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆