开发者

how to restart video if phone goes to sleep

开发者 https://www.devze.com 2023-02-25 15:34 出处:网络
So far i am making progress with a video app i am working on using the media player and a looping function. After a few tests, I am concerned the app will be a battery hog if i cannot stop the video l

So far i am making progress with a video app i am working on using the media player and a looping function. After a few tests, I am concerned the app will be a battery hog if i cannot stop the video loop when the phone reaches the sleep state. Can anyone give me a quick me a way 开发者_如何学编程to fix this?


I never implemented media player on android but i suggest that you keep the screen on with the xml attribute keepscreenon, as users watching videos are usually don't touch the screen and are likly expecting the screen not shutting down. But if you insist than i think you need to save the current time of the video in onpuase and resume the video from the saved time in onresume.


Actually I added a stop function to the media player that stops the video when the app is no longer visible on the screen. Still testing but so far its saving battery power and is functioning flawlessly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号