以前に選択したサウンドを毎秒再生する必要があるタイマーに基づく Android アプリケーションを開発しています。
問題は次のとおりです。
- または で
Media Player
実行できるオブジェクトはありませんThread
Runnable
- 音を再現するメソッドが呼び出せない
- タイマータスクで実行できません
何か思いつきますか?
ありがとう
スレッド:
public void run(){
while(!detenido) //スレッドを停止するためのブール値 {
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;
}
}
}
再生音を開始するサービスのメソッド:
パブリックボイドinto1(){
mp= MediaPlayer.create(this, R.raw.censura);
mp.start();
}