Android通过摇晃手机的频率来控制声音的频率
	通过晃动手机的频率来修改播放声音的频率。效果很给力的说。主要通过sensor来算手机摇晃的频率,摇晃的频率越高,播放声音的速度越快。
	 
	  1 /**
	  2  * @author Stay
	  3  *        通过摇晃手机的频率来改变声音的速度
	  4  */
	  5  public class ShakeSound extends Activity implements SensorEventListener,OnClickListener {
	  6     private static final float SHAKE_THRESHOLD = 50;
	  7     private static final String TAG = "ActivityTest";
	  8     private SensorManager manager;
	  9     private SoundManager sm;
	 10     private long curTime, lastUpdate;
	 11     private float last_x, last_y, last_z;
	 12     private float x,y,z;
	 13     private boolean isPlaying;
	 14     private int count = -2;
	 15     private float force;
	 16     private int audioCount = 0;
	 17     private float audioForce;
	 18     private Button btn;
	 19
	 20     @Override
	 21     protected void onCreate(Bundle savedInstanceState) {
	 22         super.onCreate(savedInstanceState);
	 23         setContentView(R.layout.main);
	 24         btn = (Button) this.findViewById(R.id.hello);
	 25         btn.setOnClickListener(this);
	 26         manager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
	 27         sm = new SoundManager(this);
	 28         sm.addSound(1, "heixiu.ogg");
	 29     }
	 30
	 31     @Override
	 32     public void onSensorChanged(SensorEvent event) {
	 33         curTime = System.currentTimeMillis();
	 34         if ((curTime - lastUpdate) > 100) {
	 35             count ++ ;
	 36             if (count < 0) {
	 37                 return;
	 38             }
	 39             if (count == 0) {
	
相关新闻>>
- 发表评论
- 
				
- 最新评论 进入详细评论页>>





