我有一个具有所需功能的应用程序.
Howerver,在某些时候会显示toast,我希望在显示祝酒词的同时播放双哔声以提醒用户显示正在显示的消息.
我不确定在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();
}
Run Code Online (Sandbox Code Playgroud)
我在res/raw中有一个名为beep的声音文件
如何在显示toast的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); …Run Code Online (Sandbox Code Playgroud)