0

我有三个功能——动画、声音、振动。所有这些单独工作都很好。我需要同时启动所有这 3 个功能并继续播放 3 秒钟然后停止。我希望每 15 秒后重复一次。实现这一点的正确方法是什么?我的振动码如下

public void vibration(){            
int dash = 1000;    
int medium_gap = 500;

long[] pattern = { 0,  // Start immediately
    dash, medium_gap,dash , medium_gap
};
// Only perform this pattern one time (-1 means "do not repeat")
v.vibrate(pattern, -1);

}

动画代码:

linear = (LinearLayout) findViewById(R.id.lay);// this line is after setContentView in onCreate

public void anim(){    
    drawable.addFrame(new ColorDrawable(Color.RED), 1000);  
    drawable.addFrame(new ColorDrawable(Color.WHITE), 500);         
    drawable.setOneShot(false);     
    linear.setBackgroundDrawable(drawable);         
    drawable.start();     
 }

使用 soundpool 的声音:

sp = new SoundPool(5, AudioManager.STREAM_NOTIFICATION, 0);
buzzer = sp.load(this, R.raw.buzzer, 0);
public void sound(){
    sp.play(buzzer, 1,1, 0, 0, 1); //start alert tone
}
4

1 回答 1

0

您需要实现线程以在指定时间内一起运行。

Thread myTime = new Thread()
{
      void run(){
           sleep(3000) //sleep untill 3 sec than stop 
           //your code
      }
}
于 2013-08-15T17:41:51.700 回答