谁能告诉我如何启动 mp3?

can anyone tell me how do I start mp3?

我正在做一个项目,我需要在 toast "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();
             }
         }
     }
 }

这是link设置闹钟http://developer.android.com/shareables/training/Scheduler.zip在你吐司后调用setAlarm(context)方法

http://developer.android.com/reference/android/app/AlarmManager.html#set(int,%20long,%20android.app.PendingIntent)

希望对您有所帮助,请注意 TYPE。

鉴于您对原始问题的澄清,听起来您想播放声音。在这种情况下你想要这样的东西:

final MediaPlayer player = MediaPlayer.create(this, R.raw.alarm);
player.start();

R.raw.alarm 是包含您要播放的声音的文件的资源。