这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

MediaMetadata() 构造函数创建新 MediaMetadata 对象。

句法

var mediaMetadata = new MediaMetadata([metadata])
					

参数

metadata 可选

The metadata parameters are as follows:

  • title : The title of the media to be played.
  • artist : The name of the artist, group, creator, etc. of the media to be played.
  • album : The name of the album, or collection, containing the media to be played.
  • artwork : An array of images associated with the playing media.

范例

The following example creates a new media session and assigns action handlers to it:

if ('mediaSession' in navigator){
  navigator.mediaSession.metadata = new MediaMetadata({
    title: "Podcast Episode Title",
    artist: "Podcast Host",
    album: "Podcast Name",
    artwork: [{src: "podcast.jpg"}]
  });
  navigator.mediaSession.setActionHandler('play', function() {});
  navigator.mediaSession.setActionHandler('pause', function() {});
  navigator.mediaSession.setActionHandler('seekbackward', function() {});
  navigator.mediaSession.setActionHandler('seekforward', function() {});
  navigator.mediaSession.setActionHandler('previoustrack', function() {});
  navigator.mediaSession.setActionHandler('nexttrack', function() {});
}
					

规范

规范 状态 注释
Media Session Standard
The definition of 'MediaMetadata()' in that specification.
草案 初始定义。

浏览器兼容性

The compatibility table in 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 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
MediaMetadata() 构造函数 Chrome 57 Edge No Firefox 71 IE No Opera Yes Safari ? WebView Android No Chrome Android 57 Firefox Android ? Opera Android No Safari iOS ? Samsung Internet Android 7.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

元数据

  • 最后修改:
  1. 媒体会话 API
  2. MediaMetadata
  3. 特性
    1. album
    2. artist
    3. artwork
    4. MediaMetadata()
    5. title
  4. Related pages for Media Session API
    1. MediaSession