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
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
playbackState | Chrome Full support 73 | Edge Full support ≤79 | Firefox No support No | IE No support No | Opera Full support Yes | Safari ? | WebView Android No support No | Chrome Android Full support 57 | Firefox Android No support No | Opera Android No support No | Safari 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.