只读
Navigator
property
mediaSession
返回
MediaSession
object that can be used to share with the browser metadata and other information about the current playback state of media being handled by a document.
This information may, in turn, be shared with the device and/or operating system in order to a device's standard media control user experience to describe and control the playback of the media.
此外,
MediaSession
接口提供
setActionHandler()
method, which lets you receive events when the user engages device controls such as either onscreen or physical play, pause, seek, and other similar controls. An internet radio app, for example, can use
setActionHandler()
to let fhe media controls on a keyboard or elsehwere on the user's device be used to control the app's media playback.
let mediaSession = navigator.mediaSession;
A
MediaSession
object the current document can use to share information about media it's playing and its current playback status. This information can include typical metadata such as the title, artist, and album name of the song being played as well as potentially one or more images containing things like album art, artist photos, and so forth.
In this example, metadata is submitted to the
mediaSession
object. Note that the code begins by ensuring that the
navigator.mediaSession
property is available before attempting to use it.
if ("mediaSession" in navigator){
navigator.mediaSession.metadata = new MediaMetadata({
title: "Podcast Episode Title",
artist: "Podcast Host",
album: "Podcast Name",
artwork: [{src: "podcast.jpg"}]
});
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Media Session Standard
The definition of 'navigator.mediaSession' in that specification. |
草案 | 初始定义。 |
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.
更新 GitHub 上的兼容性数据| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
mediaSession
|
Chrome No | Edge No | Firefox 71 | IE No | Opera No | Safari ? | WebView Android No | Chrome Android 57 | Firefox Android ? | Opera Android No | Safari iOS ? | Samsung Internet Android 7.0 |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
Navigator
activeVRDisplays
appCodeName
appName
appVersion
battery
buildID
clipboard
connection
cookieEnabled
credentials
deviceMemory
doNotTrack
geolocation
keyboard
语言
languages
locks
maxTouchPoints
mediaDevices
mediaSession
onLine
oscpu
permissions
platform
product
productSub
serviceWorker
userAgent
vendor
vendorSub
webdriver
xr