我正在开发一个基于计时器的Android应用程序,每秒钟必须播放您之前选择的声音。
问题在于:
Media Player
或Thread
Runnable
你能想到什么吗?
由于
主题:
public void run(){
而(!detenido)// Bolean停止线程
{
try {
Servicio servicios = new Servicio();
switch(segundosesperar){ //Int to select the ms to slep
case 0:
this.sleep(1500);
servicios.intento1(); //the metod with " mp.start()"
dormir = 1500;
break;
case 1:
this.sleep(1600);
servicios.intento1();
dormir = 1600;
break;
case 2:
this.sleep(1700);
servicios.intento1();
dormir = 1700;
break;
case 3:
this.sleep(1800);
servicios.intento1();
dormir = 1800;
break;
case 4:
this.sleep(1900);
servicios.intento1();
dormir = 1900;
break;
case 5:
this.sleep(2000);
servicios.intento1();
dormir = 2000;
break;
default:
this.sleep(1750);
servicios.intento1();
dormir = 1750;
break;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
piedras =piedras+1; //Counter cronometer +1
cron = piedras+"";
//Set the counter in the activity
handler.setHcron(cron);
handler.act();
cronoparaganar = cron;
if ( piedras == piedrasmodo){
tocarsirena = true;
}
}
}
服务中的Metod开始播放声音:
public void intento1(){
mp= MediaPlayer.create(this, R.raw.censura);
mp.start();
}