我正在開發基於計時器的Android應用程序,每秒必須播放您之前選擇的聲音。線程和媒體播放器的問題,定時器的聲音
這裏的問題是:
- 沒有對象可以在
Thread
運行Media Player
或Runnable
- 我不能調用播放聲音的方法
- 我不能在計時器任務運行
你能想到什麼嗎?
感謝
線:(!detenido)
公共無效的run(){
而// 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;
}
}
}
梅託德在服務啓動播放聲音:
public void intento1(){
mp= MediaPlayer.create(this, R.raw.censura);
mp.start();
}
你能分享一些你已經試過的代碼嗎? – Ganesh 2013-03-19 14:36:04
我已經做到了 – CristianCV 2013-03-19 19:48:38