我有一個具有所需功能的應用程序。在android應用程序中執行嗶聲聲音
Howerver,在特定的時間吐司顯示,我希望在顯示吐司的同時播放雙音,以提醒用戶顯示的信息。
我不確定在android中播放聲音的最佳方法是什麼,或者是否有某些我可以訪問的默認聲音用於警報。
一些指導將不勝感激!
感謝
UPDATE
我在我的主要活動文件中的以下代碼:
public void playAlertTone(final Context context){
Thread t = new Thread(){
public void run(){
MediaPlayer player = null;
int countBeep = 0;
while(countBeep<2){
player = MediaPlayer.create(context,R.raw.beep);
player.start();
countBeep+=1;
try {
Thread.sleep(player.getDuration()+100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
t.start();
}
我在資源名爲蜂鳴聲音文件/原
如何在if語句中調用此方法,其中的吐司顯示這樣2個同時發生?
更新2:
這裏就是我試圖打電話提醒方式代碼:
if (elapsedTime > hourAlert)
{
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("HOUR PASSED");
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.BOTTOM, 0, 160);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
playAlertTone(getApplicationContext()); // Edited here now call
任何想法?
發佈您正在顯示的代碼鋪設烤麪包並調用此方法 – Ravi1187342 2012-04-06 15:15:52
查看UPDATE 2下的代碼片段 – Rob 2012-04-06 15:22:31
我編輯了這個'playAlertTone(getApplicationContext());//現在編輯調用' – Ravi1187342 2012-04-06 15:27:35