使用WakeLock保持流播放 [英] Using WakeLock to Keep A Stream Playing

查看:125
本文介绍了使用WakeLock保持流播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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的?

是的,这是一个合法的用例为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:

<一个href="http://developer.android.com/reference/android/media/MediaPlayer.html#setWakeMode%28android.content.Context,%20int%29">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保持流播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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