playbackState
特性为
MediaSession
interface indicates whether the current media session is playing or paused.
let playbackState = mediaSession.playbackState; mediaSession.playbackState = playbackState;
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.
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";
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Media Session Standard
The definition of 'playbackState' in that specification. |
草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
playbackState
|
Chrome 73 | Edge ≤79 | Firefox 不支持 No | IE 不支持 No | Opera Yes | Safari ? | WebView Android 不支持 No | Chrome Android 57 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS ? | Samsung Internet Android 7.0 |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
MediaSession
metadata
playbackState