简体   繁体   English

谁能告诉我如何启动mp3?

[英]can anyone tell me how do I start 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. 我正在做一个项目,当吐司“ 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)方法

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 is the resource for the file containing the sound you want to play. R.raw.alarm是包含您要播放的声音的文件的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 谁能告诉我为什么我在logcat中收到此错误? - Can anyone tell me why do I get this error in logcat? 谁能告诉我如何通过Android应用中的消息发送经度和纬度坐标? - Can anyone tell me how do i send longitude and lattitude co-ordinate via message in android app? 我无法在数组列表中绑定联系人,有人可以告诉我我做错了什么吗? - I cannot bind the contacts in my arraylist can anyone tell me what i do wrong?ANDROID 我如何在andengine中播放mp3? - how can i play mp3 in andengine? 谁能告诉我如何在 Firebase Firestore (Android) 中存储一组自定义对象 - Can anyone tell me how can I store an array of custom objects in Firebase Firestore (Android) 谁能告诉我如何将任何格式的图像直接转换为字符串? - Can anyone tell me how i can convert any format image directly to string? 谁能告诉我有关Android的InternalStorage的信息? 我很困惑 - Can anyone tell me about InternalStorage in Android ? I am confused 谁能告诉我在这种情况下我哪里错了? - Can anyone tell me where i am wrong in this condition? 如何在下面的代码中传递参数? 谁能告诉我如何? - how to pass a parameter in below code?? can anyone tell me how? 谁能告诉我如何在软键盘上禁用Delete键? - Can anyone tell me how to disable Delete key in the soft keyboard?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM