Skip to main content

Background playback and media controls

Playback can continue when the viewer switches tab or app or locks the phone, and the stream shows in the OS media controls: the Android media notification, the iPhone lock screen and Chrome's media button. Both are on by default with every decoder, including webcodecs.

import { Vindral } from "@vindral/web-sdk"

const instance = new Vindral({
url: "https://lb.cdn.vindral.com",
channelId: "...",
backgroundPlayEnabled: true, // default: keep playing while the page is hidden
mediaSessionEnabled: true, // default: show the stream in the OS media controls
mediaSessionMetadata: {
title: "Live stream",
artwork: [{ src: "https://example.com/artwork.png", sizes: "512x512" }],
},
})

Options​

OptionDefaultBehavior
backgroundPlayEnabledtruefalse disconnects while hidden and reconnects on return. Replaces the deprecated iosBackgroundPlayEnabled.
mediaSessionEnabledtrueShows the stream in the OS media controls and routes their play and pause to the SDK.
mediaSessionMetadataPage metadataTitle, artist, album and artwork, read once at construction.

Option names across integration surfaces​

Core Web SDKvindral-player attributeEmbed / QoS query string
backgroundPlayEnabledbackground-play-enabledcore.backgroundPlayEnabled
mediaSessionEnabledmedia-session-enabledcore.mediaSessionEnabled
mediaSessionMetadatatitle and posterplayer.title and core.poster
<vindral-player
url="https://lb.cdn.vindral.com"
channel-id="..."
title="Live stream"
poster="https://example.com/artwork.png">
</vindral-player>

Background audio​

Desktop Chrome and Safari keep audio with every decoder. Audio on phones after an app switch or lock, with the stream unmuted:

DecoderAndroid ChromeiPhone Safari
mse (default)Some phones pause it; resume from the media controls.iOS pauses the video when the viewer leaves Safari or locks the phone, unless it is in PiP; resume from the lock screen.
webcodecs or wasmContinues.Continues. PiP and native fullscreen need streamToMediaElementEnabled: true.

The decoder is set with the decoders option; see WebCodecs & Offscreen Renderer.

While the page is hidden​

SituationBehavior
backgroundPlayEnabled: falseDisconnects; reconnects on return.
pause(), or pause from the media controlsDisconnects at once; playing again reconnects.
Muted and not in PiP, or paused by the browserDisconnects within 15 seconds; reconnects on return.

Media controls​

The stream shows in the controls while it is unmuted, and play and pause there reach the SDK. With several instances on a page, one owns the controls, normally the last to start playing unmuted.

GoalOptions
Keep an instance out of the controlsmediaSessionEnabled: false on that instance
Run your own Media Session handlersmediaSessionEnabled: false, and call play() and pause() from the handlers

Set them only with mediaSessionEnabled: false; handlers set later replace the SDK's. With your own handlers, mse still shows the browser's controls; webcodecs and wasm show none in Chrome and desktop Safari, and on iPhone without streamToMediaElementEnabled the audio stops under lock; see Limitations.

Limitations​

PlatformSetupLimitation
iPhoneDRMDRM always uses mse on every platform; on iPhone that means the audio keeps playing in the background only in Picture-in-Picture.
iPhonewebcodecs or wasm with both streamToMediaElementEnabled and mediaSessionEnabled offThe audio stops when the phone locks and needs a tap to resume. The SDK emits needs user input: show an unmute control, as vindral-player does with its mute button.
iPhonewebcodecs or wasm with streamToMediaElementEnabled: trueAfter a long pause from the lock screen, iOS suspends the page and the lock-screen controls disappear; reopen Safari to resume.
iPhonewebcodecs or wasm with streamToMediaElementEnabled: true, in native fullscreenAfter locking, the lock-screen controls show a play button while the audio plays.
Androidwebcodecs or wasm, page hiddenAnother app's audio, an alarm or unplugged headphones pause playback and remove the media controls; with webcodecs, so does a pause from the controls. Resume from the page.

Testing with the QoS client​

Open a link in the QoS client, unmute, then lock the phone or open PiP. In its settings, backgroundPlayEnabled is the Enable Background Play toggle; the other two options are query string only.

Decode Performance shows the active decoder and Media Session in Playback shows whether this player owns the controls.