The MediaMetadata() constructor creates a new MediaMetadata object.
new MediaMetadata()
new MediaMetadata(metadata)metadata OptionalThe metadata parameters are as follows:
album OptionalThe name of the album, or collection, containing the media to be played. It defaults to the empty string ("").
artist OptionalThe name of the artist, group, or creator, of the media to be played. It defaults to the empty string ("").
artwork OptionalAn Array of objects that represent images associated with the playing media that defaults to be an empty array. The object structure is:
srcThe URL from which the user agent fetches the image's data.
sizes OptionalSpecifies the resource in multiple sizes so the user agent doesn't have to scale a single image. It defaults to the empty string ("").
type OptionalThe 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 ("").
chapterInfo OptionalAn array of ChapterInformation object instances representing the chapter information metadata associated with the media. The object structure is:
artwork OptionalAn Array of artwork objects (see above) representing images associated with the chapter. If omitted, artwork defaults to an empty array.
startTime OptionalA number representing the chapter's start time in seconds. If omitted, startTime defaults to 0.
title OptionalA string representing the title of the chapter. If omitted, title defaults to the empty string ("").
title OptionalThe title of the media to be played. It defaults to the empty string ("").
The following example creates a new MediaMetadata object using the correct format of metadata.
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",
},
],
});
}