Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.
This repository was archived by the owner on May 23, 2025. It is now read-only.

Feature request: Use WakeLock when playing audio #4161

@mcclure

Description

@mcclure

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions