Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Media Session types #821

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,12 @@ interface MediaEncryptedEventInit extends EventInit {
initDataType?: string;
}

interface MediaImage {
sizes?: string;
src: string;
type?: string;
}

interface MediaKeyMessageEventInit extends EventInit {
message: ArrayBuffer;
messageType: MediaKeyMessageType;
Expand All @@ -689,11 +695,28 @@ interface MediaKeySystemMediaCapability {
robustness?: string;
}

interface MediaMetadataInit {
album?: string;
artist?: string;
artwork?: MediaImage[];
title?: string;
}

interface MediaPositionState {
duration?: number;
playbackRate?: number;
position?: number;
}

interface MediaQueryListEventInit extends EventInit {
matches?: boolean;
media?: string;
}

interface MediaSessionActionDetails {
action: MediaSessionAction;
}

interface MediaStreamAudioSourceOptions {
mediaStream: MediaStream;
}
Expand Down Expand Up @@ -10419,6 +10442,18 @@ declare var MediaList: {
new(): MediaList;
};

interface MediaMetadata {
album: string;
artist: string;
artwork: ReadonlyArray<MediaImage>;
title: string;
}

declare var MediaMetadata: {
prototype: MediaMetadata;
new(init?: MediaMetadataInit): MediaMetadata;
};

interface MediaQueryListEventMap {
"change": MediaQueryListEvent;
}
Expand Down Expand Up @@ -10453,6 +10488,18 @@ declare var MediaQueryListEvent: {
new(type: string, eventInitDict?: MediaQueryListEventInit): MediaQueryListEvent;
};

interface MediaSession {
metadata: MediaMetadata | null;
playbackState: MediaSessionPlaybackState;
setActionHandler(action: MediaSessionAction, handler: MediaSessionActionHandler | null): void;
setPositionState(state?: MediaPositionState): void;
}

declare var MediaSession: {
prototype: MediaSession;
new(): MediaSession;
};

interface MediaSourceEventMap {
"sourceclose": Event;
"sourceended": Event;
Expand Down Expand Up @@ -10897,6 +10944,7 @@ interface Navigator extends MSFileSaver, MSNavigatorDoNotTrack, NavigatorAutomat
readonly geolocation: Geolocation;
readonly maxTouchPoints: number;
readonly mediaDevices: MediaDevices;
readonly mediaSession: MediaSession;
readonly msManipulationViewsEnabled: boolean;
readonly msMaxTouchPoints: number;
readonly msPointerEnabled: boolean;
Expand Down Expand Up @@ -19290,6 +19338,10 @@ interface MSLaunchUriCallback {
(): void;
}

interface MediaSessionActionHandler {
(details: MediaSessionActionDetails): void;
}

interface MutationCallback {
(mutations: MutationRecord[], observer: MutationObserver): void;
}
Expand Down Expand Up @@ -20126,6 +20178,8 @@ type MediaKeyMessageType = "individualization-request" | "license-release" | "li
type MediaKeySessionType = "persistent-license" | "temporary";
type MediaKeyStatus = "expired" | "internal-error" | "output-downscaled" | "output-restricted" | "released" | "status-pending" | "usable";
type MediaKeysRequirement = "not-allowed" | "optional" | "required";
type MediaSessionAction = "nexttrack" | "pause" | "play" | "previoustrack" | "seekbackward" | "seekforward" | "seekto" | "skipad" | "stop";
type MediaSessionPlaybackState = "none" | "paused" | "playing";
type MediaStreamTrackState = "ended" | "live";
type NavigationReason = "down" | "left" | "right" | "up";
type NavigationType = "back_forward" | "navigate" | "prerender" | "reload";
Expand Down
76 changes: 76 additions & 0 deletions inputfiles/idl/Media Session.widl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[Exposed=Window]
partial interface Navigator {
[SameObject] readonly attribute MediaSession mediaSession;
};

enum MediaSessionPlaybackState {
"none",
"paused",
"playing"
};

enum MediaSessionAction {
"play",
"pause",
"seekbackward",
"seekforward",
"previoustrack",
"nexttrack",
"skipad",
"stop",
"seekto"
};

callback MediaSessionActionHandler = void(MediaSessionActionDetails details);

[Exposed=Window]
interface MediaSession {
attribute MediaMetadata? metadata;

attribute MediaSessionPlaybackState playbackState;

void setActionHandler(MediaSessionAction action, MediaSessionActionHandler? handler);

void setPositionState(optional MediaPositionState state = {});
};

[Exposed=Window]
interface MediaMetadata {
constructor(optional MediaMetadataInit init = {});
attribute DOMString title;
attribute DOMString artist;
attribute DOMString album;
attribute FrozenArray<MediaImage> artwork;
};

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

dictionary MediaImage {
required USVString src;
DOMString sizes = "";
DOMString type = "";
};

dictionary MediaPositionState {
double duration;
double playbackRate;
double position;
};

dictionary MediaSessionActionDetails {
required MediaSessionAction action;
};

dictionary MediaSessionSeekActionDetails : MediaSessionActionDetails {
double? seekOffset;
};

dictionary MediaSessionSeekToActionDetails : MediaSessionActionDetails {
required double seekTime;
boolean? fastSeek;
};
4 changes: 4 additions & 0 deletions inputfiles/idlSources.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@
"url": "https://w3c.github.io/mediacapture-main/",
"title": "Media Capture and Streams"
},
{
"url": "https://www.w3.org/TR/mediasession/",
"title": "Media Session"
},
{
"url": "https://www.w3.org/TR/media-source/",
"title": "Media Source Extensions"
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.