MediaSession.playbackState

The playbackState property of the MediaSession interface indicates whether the current media session is playing or paused.

Syntax

let playbackState = mediaSession.playbackState;
mediaSession.playbackState = playbackState;

Value

A DOMString indicating the current playback state of the media session. The value may be one of the following:

none
The browsing context doesn't currently know the current playback state, or the playback state is not available at this time.
paused
The browser's media session is currently paused. Playback may be resumed.
playing
The browser's media session is currently playing media, which can be paused.

Example

The following example sets up event handlers, for pausing and playing:

var audio = document.querySelector("#player");
audio.src = "song.mp3";

navigator.mediaSession.setActionHandler('play', play);
navigator.mediaSession.setActionHandler('pause', pause);

function play() {
   audio.play();
   navigator.mediaSession.playbackState = "playing";
}

function pause() {
   audio.pause();
   navigator.mediaSession.playbackState = "paused";
}

Specifications

Specification Status Comment
Media Session Standard
The definition of 'playbackState' in that specification.
Draft Initial definition.

Browser Compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
playbackState
Experimental
Chrome Full support 73Edge Full support ≤79Firefox Full support 76
Disabled
Full support 76
Disabled
Disabled From version 76: this feature is behind the dom.media.mediasession.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support YesSafari No support NoWebView Android No support NoChrome Android Full support 57Firefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android Full support 7.0

Legend

Full support  
Full support
No support  
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.
User must explicitly enable this feature.