feat: add MediaMetadata (#2410)

* change browserslist to cover 100% not dead browsers

* feat: add MediaMetadata

* Revert browserslist change

Co-authored-by: Sam Potts <sam@potts.es>
This commit is contained in:
Hashen 2022-02-24 18:12:58 +05:30 committed by GitHub
parent 4632614ced
commit 6bc447b916
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 1 deletions

View File

@ -413,6 +413,7 @@ Note the single quotes encapsulating the JSON and double quotes on the object ke
| `vimeo` | Object | `{ byline: false, portrait: false, title: false, speed: true, transparent: false }` | See [Vimeo embed options](https://github.com/vimeo/player.js/#embed-options). Some are set automatically based on other config options, namely: `loop`, `autoplay`, `muted`, `gesture`, `playsinline` | | `vimeo` | Object | `{ byline: false, portrait: false, title: false, speed: true, transparent: false }` | See [Vimeo embed options](https://github.com/vimeo/player.js/#embed-options). Some are set automatically based on other config options, namely: `loop`, `autoplay`, `muted`, `gesture`, `playsinline` |
| `youtube` | Object | `{ noCookie: false, rel: 0, showinfo: 0, iv_load_policy: 3, modestbranding: 1 }` | See [YouTube embed options](https://developers.google.com/youtube/player_parameters#Parameters). The only custom option is `noCookie` to use an alternative to YouTube that doesn't use cookies (useful for GDPR, etc). Some are set automatically based on other config options, namely: `autoplay`, `hl`, `controls`, `disablekb`, `playsinline`, `cc_load_policy`, `cc_lang_pref`, `widget_referrer` | | `youtube` | Object | `{ noCookie: false, rel: 0, showinfo: 0, iv_load_policy: 3, modestbranding: 1 }` | See [YouTube embed options](https://developers.google.com/youtube/player_parameters#Parameters). The only custom option is `noCookie` to use an alternative to YouTube that doesn't use cookies (useful for GDPR, etc). Some are set automatically based on other config options, namely: `autoplay`, `hl`, `controls`, `disablekb`, `playsinline`, `cc_load_policy`, `cc_lang_pref`, `widget_referrer` |
| `previewThumbnails` | Object | `{ enabled: false, src: '' }` | `enabled`: Whether to enable the preview thumbnails (they must be generated by you). `src` must be either a string or an array of strings representing URLs for the VTT files containing the image URL(s). Learn more about [preview thumbnails](#preview-thumbnails) below. | | `previewThumbnails` | Object | `{ enabled: false, src: '' }` | `enabled`: Whether to enable the preview thumbnails (they must be generated by you). `src` must be either a string or an array of strings representing URLs for the VTT files containing the image URL(s). Learn more about [preview thumbnails](#preview-thumbnails) below. |
| `mediaMetadata` | Object | `{ title: '', artist: '', album: '', artwork: [] }` | The [MediaMetadata](https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata) interface of the Media Session API allows a web page to provide rich media metadata for display in a platform UI. |
1. Vimeo only 1. Vimeo only
2. Autoplay is generally not recommended as it is seen as a negative user experience. It is also disabled in many browsers. Before raising issues, do your homework. More info can be found here: 2. Autoplay is generally not recommended as it is seen as a negative user experience. It is also disabled in many browsers. Before raising issues, do your homework. More info can be found here:

View File

@ -65,6 +65,17 @@ import toggleClass from './toggle-class';
// Prevent Vimeo blocking plyr.io demo site // Prevent Vimeo blocking plyr.io demo site
referrerPolicy: 'no-referrer', referrerPolicy: 'no-referrer',
}, },
mediaMetadata: {
title: 'View From A Blue Moon',
album: 'Sports',
artist: 'Brainfarm',
artwork: [
{
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg',
type: 'image/jpeg',
},
],
},
markers: { markers: {
enabled: true, enabled: true,
points: [ points: [

View File

@ -446,7 +446,15 @@ const defaults = {
noCookie: false, // Whether to use an alternative version of YouTube without cookies noCookie: false, // Whether to use an alternative version of YouTube without cookies
}, },
// markers // Media Metadata
mediaMetadata: {
title: '',
artist: '',
album: '',
artwork: [],
},
// Markers
markers: { markers: {
enabled: false, enabled: false,
points: [], points: [],

17
src/js/controls.js vendored
View File

@ -1749,6 +1749,23 @@ const controls = {
}); });
} }
}, },
// Set media metadata
setMediaMetadata() {
try {
if ('mediaSession' in navigator) {
navigator.mediaSession.metadata = new window.MediaMetadata({
title: this.config.mediaMetadata.title,
artist: this.config.mediaMetadata.artist,
album: this.config.mediaMetadata.album,
artwork: this.config.mediaMetadata.artwork,
});
}
// eslint-disable-next-line no-empty
} catch (e) {}
},
// Add markers
setMarkers() { setMarkers() {
if (this.duration > 0 && !this.elements.markers) { if (this.duration > 0 && !this.elements.markers) {
const { points } = this.config.markers; const { points } = this.config.markers;

18
src/js/plyr.d.ts vendored
View File

@ -518,6 +518,11 @@ declare namespace Plyr {
* Preview Thumbnails Options. * Preview Thumbnails Options.
*/ */
previewThumbnails?: PreviewThumbnailsOptions; previewThumbnails?: PreviewThumbnailsOptions;
/**
* Media Metadata Options.
*/
mediaMetadata?: MediaMetadataOptions;
} }
interface QualityOptions { interface QualityOptions {
@ -576,6 +581,19 @@ declare namespace Plyr {
src?: string | string[]; src?: string | string[];
} }
interface MediaMetadataArtwork {
src: string;
sizes?: string;
type: string;
}
interface MediaMetadataOptions {
title?: string;
artist?: string;
album?: string;
artwork?: MediaMetadataArtwork[];
}
export interface Elements { export interface Elements {
buttons: { buttons: {
airplay?: HTMLButtonElement; airplay?: HTMLButtonElement;

View File

@ -125,6 +125,11 @@ const ui = {
if (this.config.duration) { if (this.config.duration) {
controls.durationUpdate.call(this); controls.durationUpdate.call(this);
} }
// Media metadata
if (this.config.mediaMetadata) {
controls.setMediaMetadata.call(this);
}
}, },
// Setup aria attribute for play and iframe title // Setup aria attribute for play and iframe title