MediaMetadata: MediaMetadata() constructor

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The MediaMetadata() constructor creates a new MediaMetadata object.

Syntax

js
new MediaMetadata()
new MediaMetadata(metadata)

Parameters

metadata Optional

The metadata parameters are as follows:

title Optional

The title of the media to be played. It defaults to the empty string ("").

artist Optional

The name of the artist, group, creator, etc. of the media to be played. It defaults to the empty string ("").

album Optional

The name of the album, or collection, containing the media to be played. It defaults to the empty string ("").

artwork Optional

An Array of objects that represent images associated with the playing media that defaults to be an empty array. The object structure is:

src

The URL from which the user agent fetches the image's data.

sizes Optional

Specifies the resource in multiple sizes so the user agent doesn't have to scale a single image. It defaults to the empty string ("").

type Optional

The MIME type hint for the user agent that allows it to ignore images of types that it doesn't support. However, the user agent may still use MIME type sniffing after downloading the image to determine its type. It defaults to the empty string ("").

Example

The following example creates a new MediaMetadata object using the correct format of metadata.

js
if ("mediaSession" in navigator) {
  navigator.mediaSession.metadata = new MediaMetadata({
    title: "Unforgettable",
    artist: "Nat King Cole",
    album: "The Ultimate Collection (Remastered)",
    artwork: [
      {
        src: "https://dummyimage.com/96x96",
        sizes: "96x96",
        type: "image/png",
      },
      {
        src: "https://dummyimage.com/128x128",
        sizes: "128x128",
        type: "image/png",
      },
      {
        src: "https://dummyimage.com/192x192",
        sizes: "192x192",
        type: "image/png",
      },
      {
        src: "https://dummyimage.com/256x256",
        sizes: "256x256",
        type: "image/png",
      },
      {
        src: "https://dummyimage.com/384x384",
        sizes: "384x384",
        type: "image/png",
      },
      {
        src: "https://dummyimage.com/512x512",
        sizes: "512x512",
        type: "image/png",
      },
    ],
  });
}

Specifications

Specification
Media Session
# dom-mediametadata-mediametadata

Browser compatibility

BCD tables only load in the browser