Navigator.mediaSession - Web APIs 编辑

The read-only Navigator property mediaSession returns a 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.

In addition, the MediaSession interface provides the 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.

Syntax

let mediaSession = navigator.mediaSession;

Value

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.

Example

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"}]
  });
}

Specifications

SpecificationStatusComment
Media Session Standard
The definition of 'navigator.mediaSession' in that specification.
DraftInitial definition.

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:39 次

字数:3545

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文