UNPKG

4.9 kBTypeScriptView Raw
1import { BaseImageResource } from './BaseImageResource';
2import type { Dict } from '@pixi/utils';
3export interface IVideoResourceOptions {
4 autoLoad?: boolean;
5 autoPlay?: boolean;
6 updateFPS?: number;
7 crossorigin?: boolean | string;
8 loop?: boolean;
9 muted?: boolean;
10 playsinline?: boolean;
11}
12export interface IVideoResourceOptionsElement {
13 src: string;
14 mime: string;
15}
16/**
17 * Resource type for {@link HTMLVideoElement}.
18 * @memberof PIXI
19 */
20export declare class VideoResource extends BaseImageResource {
21 /** Override the source to be the video element. */
22 source: HTMLVideoElement;
23 /**
24 * `true` to use Ticker.shared to auto update the base texture.
25 * @default true
26 */
27 protected _autoUpdate: boolean;
28 /**
29 * `true` if the instance is currently connected to PIXI.Ticker.shared to auto update the base texture.
30 * @default false
31 */
32 protected _isConnectedToTicker: boolean;
33 protected _updateFPS: number;
34 protected _msToNextUpdate: number;
35 private _videoFrameRequestCallbackHandle;
36 /**
37 * When set to true will automatically play videos used by this texture once
38 * they are loaded. If false, it will not modify the playing state.
39 * @default true
40 */
41 protected autoPlay: boolean;
42 /**
43 * Promise when loading.
44 * @default null
45 */
46 private _load;
47 /** Callback when completed with load. */
48 private _resolve;
49 private _reject;
50 /**
51 * @param {HTMLVideoElement|object|string|Array<string|object>} source - Video element to use.
52 * @param {object} [options] - Options to use
53 * @param {boolean} [options.autoLoad=true] - Start loading the video immediately
54 * @param {boolean} [options.autoPlay=true] - Start playing video immediately
55 * @param {number} [options.updateFPS=0] - How many times a second to update the texture from the video.
56 * If 0, `requestVideoFrameCallback` is used to update the texture.
57 * If `requestVideoFrameCallback` is not available, the texture is updated every render.
58 * @param {boolean} [options.crossorigin=true] - Load image using cross origin
59 * @param {boolean} [options.loop=false] - Loops the video
60 * @param {boolean} [options.muted=false] - Mutes the video audio, useful for autoplay
61 * @param {boolean} [options.playsinline=true] - Prevents opening the video on mobile devices
62 */
63 constructor(source?: HTMLVideoElement | Array<string | IVideoResourceOptionsElement> | string, options?: IVideoResourceOptions);
64 /**
65 * Trigger updating of the texture.
66 * @param _deltaTime - time delta since last tick
67 */
68 update(_deltaTime?: number): void;
69 private _videoFrameRequestCallback;
70 /**
71 * Start preloading the video resource.
72 * @returns {Promise<void>} Handle the validate event
73 */
74 load(): Promise<this>;
75 /**
76 * Handle video error events.
77 * @param event
78 */
79 private _onError;
80 /**
81 * Returns true if the underlying source is playing.
82 * @returns - True if playing.
83 */
84 private _isSourcePlaying;
85 /**
86 * Returns true if the underlying source is ready for playing.
87 * @returns - True if ready.
88 */
89 private _isSourceReady;
90 /** Runs the update loop when the video is ready to play. */
91 private _onPlayStart;
92 /** Fired when a pause event is triggered, stops the update loop. */
93 private _onPlayStop;
94 /** Fired when the video is completed seeking to the current playback position. */
95 private _onSeeked;
96 /** Fired when the video is loaded and ready to play. */
97 private _onCanPlay;
98 /** Destroys this texture. */
99 dispose(): void;
100 /** Should the base texture automatically update itself, set to true by default. */
101 get autoUpdate(): boolean;
102 set autoUpdate(value: boolean);
103 /**
104 * How many times a second to update the texture from the video. If 0, `requestVideoFrameCallback` is used to
105 * update the texture. If `requestVideoFrameCallback` is not available, the texture is updated every render.
106 * A lower fps can help performance, as updating the texture at 60fps on a 30ps video may not be efficient.
107 */
108 get updateFPS(): number;
109 set updateFPS(value: number);
110 private _configureAutoUpdate;
111 /**
112 * Used to auto-detect the type of resource.
113 * @param {*} source - The source object
114 * @param {string} extension - The extension of source, if set
115 * @returns {boolean} `true` if video source
116 */
117 static test(source: unknown, extension?: string): source is HTMLVideoElement;
118 /**
119 * List of common video file extensions supported by VideoResource.
120 * @readonly
121 */
122 static TYPES: Array<string>;
123 /**
124 * Map of video MIME types that can't be directly derived from file extensions.
125 * @readonly
126 */
127 static MIME_TYPES: Dict<string>;
128}