[video.js] Add Player.MediaObject, loadMedia, getMedia (#43570)

This commit is contained in:
zhangciwu
2020-04-02 12:52:05 -07:00
committed by GitHub
parent 1825338f43
commit 8409a77939
2 changed files with 70 additions and 0 deletions
+61
View File
@@ -3863,6 +3863,56 @@ declare namespace videojs {
getTagSettings(tag: Element): any;
};
namespace Player {
/**
* An object that describes a single piece of media.
* Properties that are not part of this type description will be retained; so, this can be viewed as a generic metadata storage mechanism as well.
*/
interface MediaObject {
/**
* Unused, except if this object is passed to the MediaSession API.
*/
album?: string;
/**
* Unused, except if this object is passed to the MediaSession API.
*/
artist?: string;
/**
* Unused, except if this object is passed to the MediaSession API. If not specified, will be populated via the poster, if available.
*/
artwork?: any[];
/**
* URL to an image that will display before playback.
*/
poster?: string;
/**
* A single source object, an array of source objects, or a string referencing a URL to a media source.
* It is highly recommended that an object or array of objects is used here, so that source selection algorithms can take the type into account.
*/
src?: string | Tech.SourceObject | Tech.SourceObject[];
/**
* Unused, except if this object is passed to the MediaSession API.
*/
title?: string;
/**
* An array of objects to be used to create text tracks, following the native track element format.
* For ease of removal, these will be created as "remote" text tracks and set to automatically clean up on source changes.
*/
textTracks?: any[];
/**
* Properties that are not part of this type description will be retained; so, this can be viewed as a generic metadata storage mechanism as well.
*/
[key: string]: any;
}
}
type PlayerOptions = VideoJsPlayerOptions;
/**
@@ -6331,6 +6381,12 @@ export interface VideoJsPlayer extends videojs.Component {
*/
exitFullWindow(): void;
/**
* Get a clone of the current Player~MediaObject for this player.
* If the loadMedia method has not been used, will attempt to return a Player~MediaObject based on the current state of the player.
*/
getMedia(): videojs.Player.MediaObject;
/**
* Reports whether or not a player has a plugin available.
*
@@ -6434,6 +6490,11 @@ export interface VideoJsPlayer extends videojs.Component {
*/
load(): void;
/**
* Populate the player using a MediaObject.
*/
loadMedia(media: videojs.Player.MediaObject, ready: () => any): void;
/**
* Get or set the loop attribute on the video element.
*
+9
View File
@@ -153,6 +153,15 @@ function testPlugin(player: videojs.Player, options: {}) {
this.player.on('pause', () => {
videojs.log('playback ended');
});
const media = this.player.getMedia();
this.player.loadMedia({
src: "http://www.example.com/path/to/video.mp4",
poster: "http://www.example.com/path/to/image.jpg",
}, () => {
videojs.log('loadMedia ready!');
});
}
}