Media Session

Living Standard — Last Updated

Participate:
File an issue (open issues)
IRC: #whatwg on Freenode
Version History:
https://github.com/whatwg/mediasession/commits

Abstract

This specification enables web developers to obtain different levels of platform media focus, customize available platform media controls, and access platform media keys such as hardware keys found on keyboards, headsets, remote controls, and software keys found in notification areas and on lock screens of mobile devices.

1. Introduction

This section is non-normative.

Media is used extensively today on the web to play a variety of different types of content. It is often used to play music, podcasts and radio content. At other times web media is used to provide background music, sound effects, notification sounds and to render WebRTC media stream content.

When playing media on the web, developers are currently forced to adopt a single default platform modality for playing all media content. On the other hand, native applications can access much richer media integration options with an underlying platform. On mobile devices, native application developers can request many different forms of media integration with the platform to obtain access to headphone buttons, lock screens and notification areas as needed. On desktop devices, native applications have access to keyboard media key events. Native application developers can specify the conditions in which media content should pause or duck on audio interruptions (i.e. pause or lower the volume for the duration of an interruption), continue playing out when application focus is lost or the device screen is switched off and interface with internal and external remote controllers.

This specification provides these platform media integration features for web media. By allowing web developers to express the intended usage of their media content, user agents can supply the most suitable platform-level interactions for that content and enforce logical interoperation behavior on the current platform between any number of different sources of media.

This specification describes the mechanism that allows web developers to specify the most appropriate kind for their media content and for user agents to then use these supplied hints to enforce how different sources of web media should interact with each other, other native media content and the underlying platform.

2. Conformance

All diagrams, examples, and notes in this specification are non-normative, as are all sections explicitly marked non-normative. Everything else in this specification is normative.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119. For readability, these words do not appear in all uppercase letters in this specification. [RFC2119]

Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or "return false and terminate these steps") are to be interpreted with the meaning of the key word ("must", "should", "may", etc) used in introducing the algorithm.

Conformance requirements phrased as algorithms or specific steps may be implemented in any manner, so long as the end result is equivalent. (In particular, the algorithms defined in this specification are intended to be easy to follow, and not intended to be performant.)

User agents may impose implementation-specific limits on otherwise unconstrained inputs, e.g. to prevent denial of service attacks, to guard against running out of memory, or to work around platform-specific limitations.

When a method or an attribute is said to call another method or attribute, the user agent must invoke its internal API for that attribute or method so that e.g. the author can’t change the behavior by overriding attributes or methods with custom properties or functions in JavaScript.

Unless otherwise stated, string comparisons are done in a case-sensitive manner.

3. Dependencies

The IDL fragments in this specification must be interpreted as required for conforming IDL fragments, as described in the Web IDL specification. [WEBIDL]

4. The MediaSession interface

[Constructor(optional MediaSessionKind kind = "content")]
interface MediaSession {
  readonly attribute MediaSessionKind kind;
  attribute MediaMetadata? metadata;

  Promise<void> activate();
  Promise<void> deactivate();
};

enum MediaSessionKind {
  "content",
  "transient",
  "transient-solo",
  "ambient"
};

MediaSession objects are simply known as media sessions.

A media session has metadata, which is either a MediaMetadata object or null.

session = new MediaSession([kind])
Returns a new MediaSession object.
session . kind
Returns the media session’s kind.
session . metadata
Returns the media session’s MediaMetadata object, if any, or null otherwise.

Can be set, to a MediaMetadata object or null.

session . activate()
Requests platform-level media focus and sets the media session’s state to active.

Throws a NotAllowedError exception if the request was denied by the user agent or the platform.

session . deactivate()
Releases platform-level media focus and sets the media session’s state to idle.

The MediaSession(kind) constructor, when invoked, must return a new media session whose kind is kind, and state is idle.

The kind attribute must return the media session’s kind.

The metadata attribute, on getting, must return the media session’s metadata.

The activate() method, when invoked, must run these steps:

  1. Let media session be the context object.
  2. Let promise be a new promise.
  3. Return promise, and run the remaining steps in parallel.
  4. Activate media session.
  5. If activate failed, reject promise with a NotAllowedError exception.
  6. Otherwise, fulfill promise with undefined.

Note: activate() can fail if there is an ongoing high-priority activity, e.g. a phone call.

The deactivate() method, when invoked, must run these steps:

  1. Let media session be the context object.
  2. Let promise be a new promise.
  3. Return promise, and run the remaining steps in parallel.
  4. Deactivate media session.
  5. Fulfill promise with undefined.

Note: Unlike activate(), deactivate() cannot fail.

4.1. States

A media session has a state that describes its current status with respect to any platform-level interactions and interactions with other media sessions. The possible values are as follows:

idle
The media session does not have any platform-level media focus nor is it in a suspended state.
active
The media session currently has platform-level media focus.
interrupted
The media session is currently suspended from having platform-level media focus and its audio-producing participants are either paused or ducked based on the media session’s kind.

4.2. Kinds

A media session has a kind which is one of "content", "transient", "transient-solo" and "ambient".

The following table lists the available kinds, their associated behavior, and examples of when they are appropriate to use.
Kind Behavior Examples
"content" Music, podcasts, radio streams.
"transient" Notification sounds. Spoken driving directions where playback of music in the background is acceptable.
"transient-solo" Playback of driving directions. Other spoken notifications.
"ambient" UI sounds. In-game sound effects and background music.

4.3. Participants

An audio-producing object is any object or element that is capable of emitting sound within the user agent and is therefore also potentially capable of interacting with the media focus system available in different underlying platforms.

An audio-producing object may have a current media session, which is a media session.

A media session may have one or more audio-producing objects attached to it; called its audio-producing participants. A media session must keep a list of its audio-producing participants that consists of zero of more audio-producing objects.

A media session has a resume list that is used internally to restore audio-producing participants at the end of an interruption that were playing, or were otherwise running, when that interruption started. The resume list may consist of zero or more audio-producing objects that must also be present in the media session’s list of audio-producing participants. When a new media session is created its resume list must be empty.

When the user agent is to pause a given audio-producing object it must run the following steps:

  1. If audio-producing object is an HTMLMediaElement object, then pause media element audio-producing object and terminate these steps.
  2. If audio-producing object is an AudioContext object, then suspend web audio object audio-producing object and terminate these steps.

When the user agent is to indefinitely pause a given audio-producing object, the user agent must pause audio-producing object and, then proceed to remove it from its current media session’s list of audio-producing participants.

When the user agent is to unpause a given audio-producing object it must run the following steps:

  1. If audio-producing object is an HTMLMediaElement object, then unpause media element audio-producing object and terminate these steps.
  2. If audio-producing object is an AudioContext object, then resume web audio object audio-producing object and terminate these steps.

When an audio-producing object is to duck the user agent must ensure its output volume is lowered.

When an audio-producing object is to unduck the user agent should restore its output volume to the same level that was observed prior to the original corresponding duck request.

When an audio-producing object is ducked any reduction in volume applied by the user agent is not intended to be observable to web pages.

4.4. Activating a media session

To activate a media session, run these steps:

  1. If media session is already active, then return success.
  2. Optionally, based on platform conventions, request the most appropriate platform-level media focus for media session based on its kind.

    If this step is run and platform-level media focus can not be obtained for any reason, then return failure.

  3. Run these substeps:
    If media session’s kind is "content"
    1. Optionally, based on platform conventions, the user agent may show an ongoing media interface in the underlying platform’s notifications area and/or show an ongoing media interface in the underlying platform’s lock screen area, using any available metadata.
    If media session’s kind is "transient" or "transient-solo"
    The user agent should not provide user access to any hardware or software media keys and not display any ongoing media interface in the underlying platform’s notifications area or show any ongoing media interface in the underlying platform’s lock screen area for "transient" or "transient-solo"-based media sessions.
    If media session’s kind is "ambient"
    If media session’s top-level browsing context is not at least partially visible on at least one screen, then return failure.

    The user agent should not provide user access to any hardware or software media keys and not display any ongoing media interface in the underlying platform’s notifications area or show any ongoing media interface in the underlying platform’s lock screen area for "ambient"-based media sessions.

  4. Set media session’s resume list to an empty list.
  5. Set media session’s state to active, then return success.

4.5. Interrupting a media session

An active media session may be interrupted at any time. This typically occurs when another application or another media session requests and is granted a level of platform media focus that affects the media session based on its kind.

Interruptions can be both transient or permanent. A transient interruption means we can either choose to duck our media content and continue playing it out at a reduced volume for the duration of the interruption; or pause our media content for the duration of the interruption and, then, resume playback when that interruption ends. A permanent interruption means we must pause our media content indefinitely.

When a start-of-interruption notification event is received from the platform, then the user agent must run the media session interruption algorithm against all known media sessions, passing in each media session as media session.

The media session interruption algorithm takes one argument, media session, and consists of the following steps.

  1. If media session’s state is not active, then terminate these steps.
  2. Let interrupting kind be the kind that triggered this interruption.
  3. Run these substeps:
    If interrupting kind is "content"
    1. If media session’s kind is "content" then indefinitely pause all of media session’s audio-producing participants and set media session’s state to idle.

      This implies that the next time the media session is activated, that we will re-request media focus according to the steps defined in that algorithm.

    2. Optionally, based on platform conventions, the user agent must remove any previously established ongoing media interface in the underlying platform’s notifications area and any ongoing media interface in the underlying platform’s lock screen area for media session, if any.
    3. Optionally, based on platform conventions, the user agent must prevent any hardware and/or software media keys from controlling playback of media session’s audio-producing participants.
    If interrupting kind is "transient"
    1. If media session’s kind is not "content", then terminate these steps.
    2. For each audio-producing object in media session’s list of audio-producing participants:
      1. If audio-producing object is not currently playing, or is not otherwise running, then terminate these substeps and continue at the next available audio-producing object.
      2. Duck audio-producing object.
      3. Add audio-producing object to media session’s resume list.
    3. Set media session’s state to interrupted.

      This implies that the next time the media session continuation algorithm is run for media session that we will re-activate this media session according to the steps defined in that algorithm.

    If interrupting kind is "transient-solo"
    1. If media session’s kind is not "content", "transient" or "transient-solo", then terminate these steps.
    2. For each audio-producing object in media session’s list of audio-producing participants:
      1. If audio-producing object is not currently playing, or is not otherwise running, then terminate these substeps and continue at the next available audio-producing object.
      2. Pause audio-producing object.
      3. Add audio-producing object to media session’s resume list.
    3. Set media session’s state to interrupted.

      This implies that the next time the media session continuation algorithm is run for media session that we will re-activate this media session according to the steps defined in that algorithm.

When an end-of-interruption notification event is received from the platform, then the user agent must run the media session continuation algorithm against all known media sessions, passing in each media session as media session.

The media session continuation algorithm takes one argument, media session, and consists of the following steps.

  1. If media session’s state is not interrupted, then terminate these steps.
  2. Let interrupting kind be the kind that initially triggered this interruption.
  3. Run these substeps:
    If interrupting kind is "transient"
    1. If media session’s kind is not "content", then terminate these steps.
    2. Unduck each audio-producing object in media session’s resume list.
    3. Set media session’s resume list to an empty list.
    4. Set media session’s state to active.
    If interrupting kind is "transient-solo"
    1. If media session’s kind is not "content", "transient", or "transient-solo", then terminate these steps.
    2. Unpause each audio-producing object in media session’s resume list.
    3. Set media session’s resume list to an empty list.
    4. Set media session’s state to active.


After a visibilitychange event has been fired at a top-level browsing context, known as the browsing context, the user agent must run the following steps:

  1. If visibilityState is not "hidden" or "visible", then terminate these steps.
  2. For each media session in the browsing context with a kind of "ambient" run the following substeps:
    1. Let s be the current media session.
    2. If visibilityState is "hidden" and s’s state is active, then run the following substeps:
      1. For each audio-producing object in s’s list of audio-producing participants, run the following substeps:
        1. If audio-producing object is not currently playing, or is not otherwise running, then terminate these substeps and continue at the next available audio-producing object.
        2. Pause audio-producing object.
        3. Add audio-producing object to media session’s resume list.
      2. Set s’s state to interrupted.
      3. Terminate these substeps and continue at the next available media session.
    3. If visibilityState is "visible" and s’s state is interrupted, then run the following substeps:
      1. Unpause each audio-producing object in s’s resume list.
      2. Set s’s resume list to an empty list.
      3. Set s’s state to active.
      4. Terminate these substeps and continue at the next available media session.

4.6. Deactivating a media session

To deactivate a media session, run these steps:

  1. Indefinitely pause all of media session’s audio-producing participants.
  2. Set media session’s resume list to an empty list.
  3. Set media session’s audio-producing participants to an empty list.
  4. Run the media session deactivation algorithm for media session.

The media session deactivation algorithm takes one argument, media session, and consists of the following steps.

  1. If media session’s state is idle, then terminate these steps.
  2. If media session still has one or more audio-producing participants, then terminate these steps.
  3. Optionally, based on platform conventions, the user agent must release any currently held platform media focus for media session.
  4. Optionally, based on platform conventions, the user agent must remove any previously established ongoing media interface in the underlying platform’s notifications area and any ongoing media interface in the underlying platform’s lock screen area for media session, if any.
  5. Optionally, based on platform conventions, the user agent must prevent any hardware and/or software media keys from controlling playback of media session’s audio-producing participants.

    If the algorithm reaches this step then media session can not have any remaining audio-producing participants.

  6. Set media session’s state to idle.

    This implies that the next time the media session is activated, that we will re-request media focus according to the steps defined in that algorithm.

5. The MediaMetadata interface

[Constructor(MediaMetadataInit init)]
interface MediaMetadata {
  readonly attribute DOMString title;
  readonly attribute DOMString artist;
  readonly attribute DOMString album;
  [SameObject] readonly attribute FrozenArray<MediaImage> artwork;
};

dictionary MediaMetadataInit {
  DOMString title = "";
  DOMString artist = "";
  DOMString album = "";
  sequence<MediaImageInit> artwork = [];
};

A MediaMetadata object has a title, an artist, an album and a FrozenArray of artwork images.

The MediaMetadata(init) constructor, when invoked, must run the following steps:

  1. Let metadata be a new MediaMetadata object.
  2. Set metadata’s title to init’s title.
  3. Set metadata’s artist to init’s artist.
  4. Set metadata’s album to init’s album.
  5. Set metadata’s artwork using init’s artwork by calling the MediaImage(init) constructor.
  6. Return metadata.

The title attribute must return the MediaMetadata objects’s title.

The artist attribute must return the MediaMetadata objects’s artist.

The album attribute must return the MediaMetadata objects’s album.

The artwork attribute must return the MediaMetadata objects’s artwork images, as a FrozenArray of MediaImages. The artwork attribute can be empty.

When a user agent wants to display the MediaSession's artwork as specified in it’s metadata, it is recommended to run the following fetch steps:

  1. If metadata’s artwork is empty, then terminate these steps.
  2. If the platform supports displaying media artwork, select a prefered artwork image from metadata’s artwork.
  3. Fetch prefered artwork image’s src.

    Then, in parallel:

    1. Wait for the response.
    2. If the response’s internal response’s type is default, attempt to decode the resource as image.
    3. If the image format is supported, use the image as the artwork for display. Otherwise the fetch steps fail and terminate.

If no artwork images are fetched in the fetch steps, the user agent may have fallback behavior such as displaying an default image as artwork.

6. The MediaImage interface

[Constructor(MediaImageInit init)]
interface MediaImage {
  readonly attribute USVString src;
  readonly attribute DOMString sizes;
  readonly attribute DOMString type;
};

dictionary MediaImageInit {
  USVString src = "";
  DOMString sizes = "";
  DOMString type = "";
};

A MediaImage object has a source, a list of sizes, and a type.

The MediaImage(init) constructor, when invoked, must run the following steps:

  1. Let metadata be a new MediaImage object.
  2. Set metadata’s src to init’s src. If the URL is a relative URL, it must be resolved to an absolute URL using the document base URL.
  3. Set metadata’s sizes to init’s sizes.
  4. Set metadata’s type to init’s type.
  5. Return metadata.

The MediaImage src, sizes and type inspired from the image objects in Web App Manifest.

The src attribute must return the MediaImage object’s source. It is a URL from which the user agent can fetch the image’s data.

The sizes attribute must return the MediaImage object’s sizes. It follows the spec of sizes attribute in HTML link element, which is a string consisting of an unordered set of unique space-separated tokens which are ASCII case-insensitive that represents the dimensions of an image. Each keyword is either an ASCII case-insensitive match for the string "any", or a value that consists of two valid non-negative integers that do not have a leading U+0030 DIGIT ZERO (0) character and that are separated by a single U+0078 LATIN SMALL LETTER X or U+0058 LATIN CAPITAL LETTER X character. The keywords represent icon sizes in raw pixels (as opposed to CSS pixels). When multiple image objects are available, a user agent may use the value to decide which icon is most suitable for a display context (and ignore any that are inappropriate). The parsing steps for the sizes attribute must follow the parsing steps for HTML link element sizes attribute.

The type attribute must return the MediaImage object’s type. It is a hint as to the media type of the image. The purpose of this attribute is to allow a user agent to ignore images of media types it does not support.

7. Extensions to the HTMLMediaElement interface

partial interface HTMLMediaElement {
  attribute MediaSession? session;
};
media . session [ = session ]
Returns the current media session for the media element, if any, or null otherwise.

Can be set, to change the current media session.

Throws an InvalidStateError exception if the media element’s networkState is NETWORK_LOADING or NETWORK_IDLE.

The session attribute on a media element, on getting, must return the element’s current media session, if any, or null otherwise. On setting, the user agent must run the following steps:

  1. If the media element’s networkState is NETWORK_LOADING or NETWORK_IDLE, throw an InvalidStateError exception and abort these steps.
  2. Set the media elements’s current media session to the new value.

7.1. Activating a media session from an HTMLMediaElement object

When the play() method on a media element is invoked from script – or a media element is otherwise played from the web page (e.g. via its controls) – and that media element’s paused attribute is true and its readyState attribute has the value HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA then the user agent must run the following steps, passing in media element as media element:

  1. Let media session be the value of media element’s current media session.
  2. If media element is not currently in media session’s list of audio-producing participants, then append media element to this list.
  3. Activate media session.
  4. If activate failed, pause media element.

7.2. Interrupting a media session from an HTMLMediaElement object

When the user agent is to pause a media element for a given media element it must run that media element’s internal pause steps.

When the user agent is to unpause a media element for a given media element it must invoke that media element’s play() method.

7.3. Deactivating a media session from an HTMLMediaElement object

When a media element’s playback has ended, the user agent must release media element from its media session.

Any time a media element’s load algorithm is run by the user agent, it must release media element from its media session.

When the user agent is to release media element from its media session for a given media element it must run the following steps:

  1. Let media session be the value of media element’s current media session.
  2. If media element is not currently in media session’s list of audio-producing participants, then terminate these steps.
  3. If media element is in media session’s resume list then remove it from this list.
  4. Remove media element from media session’s list of audio-producing participants.
  5. Run the media session deactivation algorithm for media session.

8. Extensions to the AudioContext interface

partial interface AudioContext {
  attribute MediaSession? session;
};
context . session [ = session ]
Returns the current media session for the AudioContext object, if any, or null otherwise.

Can be set, to change the current media session.

Throws an InvalidStateError exception if the AudioContext object’s state attribute is "running".

The session attribute on an AudioContext object, on getting, must return the object’s current media session, if any, or null otherwise. On setting, the user agent must run the following steps:

  1. If the AudioContext object’s state attribute is "running", throw an InvalidStateError exception and abort these steps.
  2. Set the AudioContext object’s current media session to the new value.

8.1. Interrupting a media session from an AudioContext object

When the user agent is to suspend a web audio object for a given AudioContext object it must invoke that AudioContext object’s suspend() method.

When the user agent is to resume a web audio object for a given AudioContext object it must invoke that AudioContext object’s resume() method.

9. Examples

This section is non-normative.

For music or podcasts, using a media session of kind "content" can be appropriate.
var audio = document.createElement("audio");
audio.src = "podcast.mp3";
audio.session = new MediaSession(); // "content" is the default kind
audio.play();

If metadata is available, providing it will allow for a richer user interface:

audio.session.metadata = new MediaMetadata({
  title: "Episode Title",
  artist: "Podcast Host",
  album: "Podcast Title",
  artwork: [{src: "podcast.jpg"}]
});

Alternatively, providing multiple artwork images in the metadata can let the user agent be able to select different artwork images for different display purposes and better fit for different screens:

audio.session.metadata = new MediaMetadata({
  title: "Episode Title",
  artist: "Podcast Host",
  album: "Podcast Title",
  artwork: [
    {src: "podcast.jpg", sizes: "128x128", type: "image/jpeg"},
    {src: "podcast_hd.jpg", sizes: "256x256"},
    {src: "podcast_xhd.jpg", sizes: "1024x1024", type: "image/jpeg"},
    {src: "podcast.png", sizes: "128x128", type: "image/png"},
    {src: "podcast_hd.png", sizes: "256x256", type: "image/png"},
    {src: "podcast.ico", sizes: "128x128 256x256", type: "image/x-icon"}
  ]
});

For example, if the user agent wants to use an image as icon, it may choose "podcast.jpg" or "podcast.png" for a low-pixel-density screen, and "podcast_hd.jpg" or "podcast_hd.png" for a high-pixel-density screen. If the user agent want to use an image for lockscreen background, "podcast_xhd.jpg" will be prefered.

For playlists or chapters of an audio book, multiple media elements can share a single media session.
var audio1 = document.createElement("audio");
audio1.src = "chapter1.mp3";

var audio2 = document.createElement("audio");
audio2.src = "chapter2.mp3";

var sharedSession = new MediaSession();
audio1.session = audio2.session = sharedSession;

audio1.play();
audio1.addEventListener("ended", function() {
  audio2.play();
});

Because the session is shared, the metadata must be updated to reflect what is currently playing.

function updateMetadata(event) {
  sharedSession.metadata = new MediaMetadata({
    title: event.target == audio1 ? "Chapter 1" : "Chapter 2",
    artist: "An Author",
    album: "A Book",
    artwork: [{src: "cover.jpg"}]
  });
}

audio1.addEventListener("play", updateMetadata);
audio2.addEventListener("play", updateMetadata);
For games, using a media session of kind "ambient" can be appropriate. Because AudioContext objects are created in the "running" state, it’s necessary to suspend before setting the session.
var context = new AudioContext();
context.suspend().then(function() {
  context.session = new MediaSession("ambient");
  context.resume();
});

Acknowledgments

The editor would like to thank Paul Adenot, Jake Archibald, Tab Atkins, Jonathan Bailey, Marcos Caceres, Domenic Denicola, Ralph Giles, Anne van Kesteren, Tobie Langel, Michael Mahemoff, Jer Noble, Elliott Sprehn, Chris Wilson, and Jörn Zaefferer for their participation in technical discussions that ultimately made this specification possible.

Special thanks go to Philip Jägenstedt and David Vest for their help in designing every aspect of media sessions and for their seemingly infinite patience in working through the initial design issues; Jer Noble for his help in building a model that also works well within the iOS audio focus model; and Mounir Lamouri and Anton Vayvod for their early involvement, feedback and support in making this specification happen.

This standard is written by Rich Tibbett (Opera, richt@opera.com).

Per CC0, to the extent possible under law, the editors have waived all copyright and related or neighboring rights to this work.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[APPMANIFEST]
Marcos Caceres; et al. Web App Manifest. 14 July 2016. WD. URL: https://w3c.github.io/manifest/
[FETCH]
Anne van Kesteren. Fetch Standard. Living Standard. URL: https://fetch.spec.whatwg.org/
[HTML]
Ian Hickson. HTML Standard. Living Standard. URL: https://html.spec.whatwg.org/multipage/
[PAGE-VISIBILITY]
Jatinder Mann; Arvind Jain. Page Visibility (Second Edition). 29 October 2013. REC. URL: https://www.w3.org/TR/page-visibility/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119
[WEBAUDIO]
Paul Adenot; Chris Wilson; Chris Rogers. Web Audio API. 8 December 2015. WD. URL: https://webaudio.github.io/web-audio-api/
[WEBIDL]
Cameron McCormack; Boris Zbarsky. WebIDL Level 1. 8 March 2016. CR. URL: https://heycam.github.io/webidl/
[WHATWG-DOM]
Anne van Kesteren. DOM Standard. Living Standard. URL: https://dom.spec.whatwg.org/
[WHATWG-URL]
Anne van Kesteren. URL Standard. Living Standard. URL: https://url.spec.whatwg.org/

IDL Index

[Constructor(optional MediaSessionKind kind = "content")]
interface MediaSession {
  readonly attribute MediaSessionKind kind;
  attribute MediaMetadata? metadata;

  Promise<void> activate();
  Promise<void> deactivate();
};

enum MediaSessionKind {
  "content",
  "transient",
  "transient-solo",
  "ambient"
};

[Constructor(MediaMetadataInit init)]
interface MediaMetadata {
  readonly attribute DOMString title;
  readonly attribute DOMString artist;
  readonly attribute DOMString album;
  [SameObject] readonly attribute FrozenArray<MediaImage> artwork;
};

dictionary MediaMetadataInit {
  DOMString title = "";
  DOMString artist = "";
  DOMString album = "";
  sequence<MediaImageInit> artwork = [];
};

[Constructor(MediaImageInit init)]
interface MediaImage {
  readonly attribute USVString src;
  readonly attribute DOMString sizes;
  readonly attribute DOMString type;
};

dictionary MediaImageInit {
  USVString src = "";
  DOMString sizes = "";
  DOMString type = "";
};

partial interface HTMLMediaElement {
  attribute MediaSession? session;
};

partial interface AudioContext {
  attribute MediaSession? session;
};