Video
The Video class provides video playback functionality similar to the
HTMLVideoElement
in web browsers. Since nx.js has no DOM, the video does not render itself —
the application explicitly draws the current frame each render pass, just
like drawing a <video> onto a <canvas>:
const ctx = screen.getContext('2d');
const video = new Video();
video.loop = true;
video.src = 'romfs:/attract.webm';
video.addEventListener('canplay', () => video.play());
function render() {
ctx.drawImage(video, 0, 0, screen.width, screen.height);
requestAnimationFrame(render);
}
requestAnimationFrame(render);Supported Video Formats
Any container/codec supported by FFmpeg's software decoders, e.g. WebM (VP8/VP9), MP4/MKV (H.264/H.265), and AV1 — with audio tracks (Vorbis, Opus, AAC, MP3, …) played through the Web Audio engine, synchronized to the audio clock.
Note
Decoding runs in software on the CPU. 720p30 is comfortable; 1080p depends on the codec and content — measure before shipping.
Extends
Constructors
new Video()
new Video(src?): Video
Parameters
| Parameter | Type |
|---|---|
src? | string |
Returns
Overrides
Properties
| Property | Type |
|---|---|
oncanplay | null | (this, ev) => any |
oncanplaythrough | null | (this, ev) => any |
onended | null | (this, ev) => any |
onerror | null | (this, ev) => any |
onloadedmetadata | null | (this, ev) => any |
onpause | null | (this, ev) => any |
onplay | null | (this, ev) => any |
onseeked | null | (this, ev) => any |
onseeking | null | (this, ev) => any |
ontimeupdate | null | (this, ev) => any |
Accessors
currentSrc
get currentSrc(): string
Returns
string
currentTime
get currentTime(): number
set currentTime(val): void
Parameters
| Parameter | Type |
|---|---|
val | number |
Returns
number
duration
get duration(): number
Returns
number
ended
get ended(): boolean
Returns
boolean
loop
get loop(): boolean
set loop(val): void
Parameters
| Parameter | Type |
|---|---|
val | boolean |
Returns
boolean
muted
get muted(): boolean
set muted(val): void
Parameters
| Parameter | Type |
|---|---|
val | boolean |
Returns
boolean
paused
get paused(): boolean
Returns
boolean
readyState
get readyState(): number
Returns
number
seeking
get seeking(): boolean
Returns
boolean
src
get src(): string
set src(val): void
Parameters
| Parameter | Type |
|---|---|
val | string |
Returns
string
videoHeight
get videoHeight(): number
The intrinsic height (in pixels) of the video, or 0 before
loadedmetadata.
Returns
number
videoWidth
get videoWidth(): number
The intrinsic width (in pixels) of the video, or 0 before
loadedmetadata.
Returns
number
volume
get volume(): number
set volume(val): void
Parameters
| Parameter | Type |
|---|---|
val | number |
Returns
number
HAVE_CURRENT_DATA
get static HAVE_CURRENT_DATA(): number
Returns
number
HAVE_ENOUGH_DATA
get static HAVE_ENOUGH_DATA(): number
Returns
number
HAVE_FUTURE_DATA
get static HAVE_FUTURE_DATA(): number
Returns
number
HAVE_METADATA
get static HAVE_METADATA(): number
Returns
number
HAVE_NOTHING
get static HAVE_NOTHING(): number
Returns
number
Methods
addEventListener()
addEventListener(type, callback, options?): void
Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
Parameters
| Parameter | Type |
|---|---|
type | string |
callback | null | EventListenerOrEventListenerObject<any> |
options? | boolean | AddEventListenerOptions |
Returns
void
Inherited from
See
https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener
dispatchEvent()
dispatchEvent(event): boolean
Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
Parameters
| Parameter | Type |
|---|---|
event | Event |
Returns
boolean
Overrides
See
https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent
getVideoPlaybackQuality()
getVideoPlaybackQuality(): VideoPlaybackQuality
Returns metrics about the video frames that have been presented and dropped.
Returns
See
https://developer.mozilla.org/docs/Web/API/HTMLVideoElement/getVideoPlaybackQuality
load()
load(): void
Returns
void
pause()
pause(): void
Returns
void
play()
play(): Promise<void>
Returns
Promise<void>
removeEventListener()
removeEventListener(type, callback, options?): void
Removes the event listener in target's event listener list with the same type, callback, and options.
Parameters
| Parameter | Type |
|---|---|
type | string |
callback | null | EventListenerOrEventListenerObject<any> |
options? | boolean | EventListenerOptions |
Returns
void
Inherited from
EventTarget.removeEventListener
See
https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener