Riff / Built on the open web / Media

Screen Wake Lock

Keeps the screen on while a video plays in Now Playing, and only then.

Now Playing on a wide screen: the Song and Video switch at the top, the cover on the left, the Up next list on the right, and the player bar along the bottom
With Video selected at the top and the dialog open, the screen is held awake.

How Riff uses it

One function computes a single condition: a video is playing, Now Playing is open, and the page is visible. When that becomes true it requests a screen lock. When it becomes false it releases it. It runs from the video's play, pause and ended events, the player's open and close events, and visibility changes.

Why

Without it a phone would dim and lock partway through a video.

Without it

The call is guarded by navigator.wakeLock and a try/catch, so the screen follows the system timeout.

Where

Links open the source at the commit this page was published from.

Reference: Screen Wake Lock on MDN.