谁能告诉我如何启动mp3? [英] can anyone tell me how do I start mp3?
本文介绍了谁能告诉我如何启动mp3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个项目,当吐司"Fall Detected"出现20秒钟时,我需要自动启动mp3或任何响亮的声音.
I am making a project ,I need to start mp3 or any loud sound automatically when the toast "Fall Detected" appears for 20 second.
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();
}
}
}
}
推荐答案
对原始问题的澄清,听起来像是您想播放声音.在这种情况下,您需要以下内容:
Given your clarifications to the original question it sounds like you want to play a sound. In which case you want something like:
final MediaPlayer player = MediaPlayer.create(this, R.raw.alarm);
player.start();
R.raw.alarm
是包含您要播放的声音的文件的资源.
R.raw.alarm
is the resource for the file containing the sound you want to play.
这篇关于谁能告诉我如何启动mp3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文