问题描述
我有一个MediaPlayer的一个服务,它是从一个URL(流)播放音频运行。截至目前它似乎很好地工作,甚至继续当我把手机在待机播放。
I have a MediaPlayer running in a Service that's playing audio from a URL (streaming). As of now it appears to work well, and even continues playing when I put the phone in standby.
我目前还没有获得一个wakelock。我的问题是:
I currently do not acquire a wakelock. My question is:
- 它实际上是需要获得一个wakelock在我的处境?
- 如果有必要,我应该购买什么类型的wakelock的?
推荐答案
MediaPlayer的不为你自动在默认情况下做到这一点。
MediaPlayer does not do this for you automatically by default.
不过,而不是你有获得唤醒锁,它有一个方法,你可以打电话来告诉它持有一个给你,而播放:
However, instead of you having to acquire a wake lock, it has a method you can call to tell it to hold one for you while playing:
http://developer.android.com/reference/android/media/MediaPlayer.html#setWakeMode(android.content.Context, INT)
需要注意的是,如文档说,它仍然是您的应用程序持有唤醒锁所以要使用此功能,您将需要请求之后锁定许可。
Note that, as the documentation says, it is still your app holding the wake lock so to use this function you will need to request the wake lock permission.
这篇关于使用WakeLock保持流播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!