简体   繁体   English

PARTIAL_WAKE_LOCK杀死了我的媒体播放器

[英]PARTIAL_WAKE_LOCK kills my mediaplayer

I implemented a wakelock to avoid stopping my MediaPlayer (playing local files only) when screen goes off. 我实现了一个唤醒锁,以避免在屏幕关闭时停止我的MediaPlayer(仅播放本地文件)。 Since I don't want to drain battery, I tried a PARTIAL_WAKE_LOCK. 由于我不想耗尽电池,我尝试了PARTIAL_WAKE_LOCK。 But it has no effect: screen off kills my player. 但它没有效果:屏幕关闭会杀死我的播放器。 FULL_WAKE_LOCK works fine, but screen stays on, as expected, draining the battery... FULL_WAKE_LOCK工作正常,但屏幕保持打开,正如预期的那样,耗尽电池......

What am I doing wrong? 我究竟做错了什么?

Thanks! 谢谢! L. L.

It looks like you are using the wake lock for the wrong purpose. 看起来您使用唤醒锁是出于错误的目的。 From what I understood based on your explanation: you need the playback to continue when the screen goes off: 根据您的解释我的理解:您需要在屏幕熄灭时继续播放:

To do that - I would recommend you try the following logic. 要做到这一点 - 我建议你尝试以下逻辑。

  • Try to have the player running in a service (not in the activity) 尝试让玩家在服务中运行(不在活动中)
  • Start the service with startForeground method (this will need you to include a notification as well) 使用startForeground方法启动服务(这也需要您包含通知)
  • Use a Messenger to communicate between your activity and service. 使用Messenger在您的活动和服务之间进行通信。

But the wake lock may come handy; 但唤醒锁定可能会派上用场; as this may be helpful in handling a audio stutter issue in future. 因为这可能有助于将来处理音频口吃问题。 I am not very sure about this part as I myself is yet to try out the wake lock as a solution to stuttering issue. 我不太确定这个部分,因为我自己还没有尝试使用唤醒锁作为解决口吃问题的方法。

(I am not a professional/commercial programmer ; rather an ad-hoc developer who finds a requirement designs a solution, develops it and uses it for myself. So my solution might not be a 100% professional approach but I am sure it does the job) (我不是一个专业/商业程序员;而是一个特殊的开发人员,他发现需求设计一个解决方案,开发它并为我自己使用它。所以我的解决方案可能不是100%的专业方法,但我相信它确实工作)

Good Luck and happy coding - S.Mani 祝你好运,编码愉快 - S.Mani

Wake Lock is to make sure the device does NOT go into standby. 唤醒锁定是为了确保设备不会进入待机状态。

What you want is to listen for Intent.ACTION_SCREEN_OFF that tells you that the screen is now off 你想要的是听Intent.ACTION_SCREEN_OFF ,它告诉你现在屏幕已关闭

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM