[英]can anyone tell me how do I start mp3?
我正在做一個項目,當吐司“ Fall Detected”出現20秒鍾時,我需要自動啟動mp3或任何響亮的聲音。
public void onSensorChanged(SensorEvent event)
{
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
{
long curTime = System.currentTimeMillis();
if ((curTime - mLastShakeTime) > MIN_TIME_BETWEEN_SHAKES_MILLISECS)
{
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
double acceleration = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)) - SensorManager.GRAVITY_EARTH;
Log.d("mySensor", "Acceleration is " + acceleration + "m/s^2");
if (acceleration < -9.00f && acceleration> -15.00f )
{
mLastShakeTime = curTime;
Toast.makeText(getApplicationContext(), "FALL DETECTED",
Toast.LENGTH_LONG).show();
}
}
}
}
這是設置警報的鏈接http://developer.android.com/shareables/training/Scheduler.zip在顯示吐司之后,調用setAlarm(context)方法
考慮到您對原始問題的澄清,聽起來您想播放聲音。 在這種情況下,您需要類似:
final MediaPlayer player = MediaPlayer.create(this, R.raw.alarm);
player.start();
R.raw.alarm
是包含您要播放的聲音的文件的資源。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.