不播放音频从睡眠模式(安卓)惊醒时, [英] Audio will not play when awakened from sleep mode (android)

查看:188
本文介绍了不播放音频从睡眠模式(安卓)惊醒时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Android应用程序报警。我可以得到活动拿出没事的时候触发报警(它唤醒了电话后,关闭键盘保护,并显示报警视图),但我不能为我的生命得到了警报声,如果设备处于睡眠模式时,警报就会响起。 (这听起来很好时,该设备是清醒和键盘锁定)。我使用的是唤醒锁。我使用的MediaPlayer,并没有成功的Soundpool尝试。是否有某种权限,我很想念? (我已经有WAKE_LOCK,DISABLE_KEYGUARD和RECEIVE_BOOT_COMPLETED权限。)

I'm writing an Android alarm app. I can get the activity to come up all right when the alarm is triggered (it wakes the phone up, turns off the keyguard and shows the alarm view), but I can't for the life of me get the alarm to sound if the device is in sleep mode when the alarm goes off. (It does sound perfectly when the device is awake and the keyguard is on.) I am using a wake lock. I've tried using the MediaPlayer and the SoundPool with no success. Is there some kind of permission that I'm missing? (I already have WAKE_LOCK, DISABLE_KEYGUARD, and RECEIVE_BOOT_COMPLETED permissions.)

在调试使用我执行它返回一​​个有效的声音ID整数(1)负载的Soundpool,但听者的onLoadComplete(这是哪里的声音被饰)是永远不会被解雇。它触发就好了,当设备被唤醒。

When debugging using the SoundPool I perform the load which returns a valid sound ID integer (1), but the onLoadComplete listener (this is where the sound gets played) is never fired. It fires just fine when the device is awake.

任何人在那里有任何意见或遇到了同样的问题?

Anyone out there have any ideas or have run into the same problem?

推荐答案

找到了解决办法!我必须调用在类的OnCreate()方法播放音频。我把它移植到onResume(),因为这是当你知道该设备是完全清醒的活动是可见的,在顶部和关注的焦点。

Found the solution! I had the call to play the audio in the onCreate() method of the class. I moved it to onResume() as this is when you know the device is fully awake and the activity is visible, on top and in focus.

这篇关于不播放音频从睡眠模式(安卓)惊醒时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆