Android - 媒体播放器 + PowerManager.PARTIAL_WAKE_LOCK
我正在创建通过 WiFi 收听广播流的应用程序3G网络。
我正在使用本机 MediaPlayer。不幸的是,当屏幕变黑并且手机进入待机模式时,媒体播放器开始停止播放音乐。
我添加了:
mp.setWakeMode(myContext, PowerManager.PARTIAL_WAKE_LOCK);
但几乎没有任何变化(只是停止播放并在接下来的 3 秒内再次开始播放..)只有 FULL_WAKE_LOCK 和 SCREEN_DIM_WAKE_LOCK 正在按我的预期工作...
在我的设备中,我设置了阻止 wifi 的选项睡觉。
我试图添加我的自定义 WAKE_LOCK
mp.setWakeMode(this.getBaseContext(), PowerManager.PARTIAL_WAKE_LOCK);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "testa");
wl.acquire();
但效果不佳。只有 FULL_WAKE_LOCK 有效,但我不想在屏幕打开时耗尽电池:(。
我有 Android 2.2 的 HTC Desire。您有什么想法如何防止 MediaPlayer 在电话处于待机模式时停止播放网络广播流吗?
I'm creating application for listening radio streams via WiFi & 3G network.
I am using native MediaPlayer. Unfortunately when screen goes black and phone goes into standby mode mediaplayer starts stopping playing the music.
I have added:
mp.setWakeMode(myContext, PowerManager.PARTIAL_WAKE_LOCK);
But there wasn't almost any change (just stop playing and in the next 3 seconds start playing again..) only FULL_WAKE_LOCK and SCREEN_DIM_WAKE_LOCK is working as I expected...
In my device I have set option that prevents wifi to sleep.
I was trying to add my cusom WAKE_LOCK
mp.setWakeMode(this.getBaseContext(), PowerManager.PARTIAL_WAKE_LOCK);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "testa");
wl.acquire();
But it didn't work as well. Only FULL_WAKE_LOCK works, but I do not want to drain battery with screen on :(.
I have HTC Desire with Android 2.2. Do you have any ideas how to prevent MediaPlayer stop playing internet radio stream while telephone is in standby mode?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Jerry 指出的,如果流是通过 WiFi 传输的,您可能需要保持 WiFi 锁定。另一件事是,你什么时候获取唤醒锁?您应该在应用程序启动时获取它,而不是等待屏幕关闭。您可能无法在设备进入睡眠状态之前获取唤醒锁。此外,如果您还没有 WAKE_LOCK 权限,则需要该权限。
As Jerry points out, you may need to keep a WiFi lock is the stream is coming over WiFi. The other thing is, when are you acquiring the wakelock? You should acquire it when your app starts, not wait for the screen to go off. You may not be able to acquire the wakelock before the device goes to sleep. Also, you will need the WAKE_LOCK permission if you don't already have it.