Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Use WakeLock when playing audio #4161

Open
mcclure opened this issue Dec 10, 2023 · 0 comments
Open

Feature request: Use WakeLock when playing audio #4161

mcclure opened this issue Dec 10, 2023 · 0 comments

Comments

@mcclure
Copy link
Collaborator

mcclure commented Dec 10, 2023

In v23, we used the default Android video player. While video or audio were playing with this player, the device would not dim or sleep, it just stayed on. Exoplayer, by default, does not do this; in v24 either audio or video will dim, then switch off, when they are left playing. This is a regression.

The documentation here: https://developer.android.com/training/scheduling/wakelock explainshttps://developer.android.com/training/scheduling/wakelock explains that there are several ways of keeping a Android device "awake", depending on what you want to do:

  • There is a FLAG_KEEP_SCREEN_ON on Activities, which will keep the screen lit and also prevent sleeping; it does not require any special permissions.
  • There is also WakeLock, which comes in several forms and does require a special permission. If we want to use a WakeLock, the way we should do this is using Exoplayer setWakeMode. This comes in two flavors, each of which will require requesting an additional permission:
    • WAKE_MODE_LOCAL, which allows the screen to dim and then sleep but which keeps the CPU on. The documentation says: "It should be used together with a foreground android.app.Service for use cases where playback occurs and the screen is off (e.g. background audio playback)."
    • WAKE_MODE_NETWORK, which will prevent the CPU from sleeping and will prevent the wifi from sleeping.

In my opinion, what we want is to use FLAG_KEEP_SCREEN_ON when playing video and use WAKE_MODE_LOCAL when we are playing audio. But there are two things I am uncertain about:

  • Do we want WAKE_MODE_NETWORK? It seems like this is mainly for players that stream audio; we want WAKE_MODE_NETWORK when we are initially downloading the audio, but afterward we will want to relinquish it. I am not sure if this is possible and I don't know if there is something else we were already doing which will prevent device/network sleep while we are loading a video.
  • What are they saying about "a foreground Service"? Does this mean that if we want to continue playing audio after screen sleep (because, I guess, at that point even if the CPU is still active, our activity suspends?) we will need to pass video playback off to a service? Can we use the service we already have (for network stuff etc) for this purpose?

Since I am not sure about the above, my proposal is that we merge FLAG_KEEP_SCREEN_ON (#4160) immediately and ship it as part of 24.1, and then we figure out WAKE_MODE for the 25.0 release. I believe 23.0 was using FLAG_KEEP_SCREEN_ON but not WAKE_MODE, so even if FLAG_KEEP_SCREEN_ON by itself is "incorrect" (because it keeps the screen on while audio is playing), it at least matches the 23.0 behavior.

I have a PR for FLAG_KEEP_SCREEN_ON #4160 (propose for 24.1), which works in testing, and a PR for WAKE_MODE #4162 , which does not work and I don't know how to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant