大网数据广告活动
Web 标准与前端开发

ChapterInformation

· 52CE 我爱测

The **`ChapterInformation`** interface of the Media Session API represents the metadata for an individual chapter of a media resource (i.e., a video or audio file).

Media Session API

The ChapterInformation interface of the Media Session API represents the metadata for an individual chapter of a media resource (i.e., a video or audio file).

The chapter information for a given media resource is set when it is first created, via the chapterInfo property of the MediaMetadata.MediaMetadata constructor's initialization object. The property takes an array of ChapterInformation objects as its value.

You can access the chapter information for an existing MediaMetadata object via its MediaMetadata.chapterInfo property. This returns an array of ChapterInformation objects.

Instance properties

  • ChapterInformation.artwork
    • : Returns an Array of objects representing images associated with the chapter.
  • ChapterInformation.startTime
    • : Returns a number, in seconds, representing the start time of the chapter.
  • ChapterInformation.title
    • : Returns a string representing the title of the chapter.

Examples

The sample code below from Video / Media Session Sample shows a typical structure for the ChapterInformation object:

const BASE_URL = "https://storage.googleapis.com/media-session/";

const metadata = {
  // …
  chapterInfo: [
    {
      title: "Chapter 1",
      startTime: 0,
      artwork: [
        {
          src: `${BASE_URL}sintel/chapter1-128.png`,
          sizes: "128x128",
          type: "image/png",
        },
        {
          src: `${BASE_URL}sintel/chapter1-512.png`,
          sizes: "512x512",
          type: "image/png",
        },
      ],
    },
    {
      title: "Chapter 2",
      startTime: 37,
      artwork: [
        {
          src: `${BASE_URL}sintel/chapter2-128.png`,
          sizes: "128x128",
          type: "image/png",
        },
        {
          src: `${BASE_URL}sintel/chapter2-512.png`,
          sizes: "512x512",
          type: "image/png",
        },
      ],
    },
  ],
};

The following snippet shows how it can be used inside Media Session code (the above object property is part of the playlist object referenced below):

function updateMetadata() {
  const track = playlist[index];

  log(`Playing ${track.title} track...`);
  navigator.mediaSession.metadata = new MediaMetadata({
    title: track.title,
    artist: track.artist,
    artwork: track.artwork,
    chapterInfo: track.chapterInfo,
  });

  // …
}

Specifications

Browser compatibility

See also

  • MediaMetadata

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。