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 No support NoIE ? Opera No support NoSafari ? WebView Android No support NoChrome Android Full support 57Firefox Android No support NoOpera Android No support NoSafari iOS ? Samsung Internet Android Full support 7.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.