- Version
- 1.0.0
- License
- MIT
- Requires
- DomSmith
- AsyncTask
- ExtendedMediaError
- Looper
- object
- scriptLoader
- Source
- YouTube.js, line 23
Constructor
new YouTube(player, parent, options)
Creates an instance of the YouTube engine.
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
player |
Player |
Reference to the player instance. |
||||||
parent |
Object |
Reference to the parent component (unused for engines). |
||||||
options |
Object |
Additional options.
|
Members
private #config :Object
Holds the instance configuration for this component.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
lazyLoadLib
|
boolean | optional | true | If |
noCookie
|
boolean | optional | true | If |
- Type
- Object
- Source
- YouTube.js, line 31
private #player :Player
Reference to the main player instance.
- Type
- Player
- Source
- YouTube.js, line 40
private #apiKey :symbol
Secret key only known to the player instance and initialized components. Used to restrict access to API methods in secure mode.
- Type
- symbol
- Source
- YouTube.js, line 47
private #youtubePlayer :Object
Reference to the YouTube player instance (IFrame API).
- Type
- Object
- Source
- YouTube.js, line 53
private #metaData :Media~metaData
Holds metadata information provided by media.load.
- Type
- Media~metaData
- Source
- YouTube.js, line 59
private #loadTask :AsyncTask
Reference to the Async Task instance. Used to handle async tasks, which can be cancelled, resolved or rejected.
- Type
- AsyncTask
- Source
- YouTube.js, line 65
private #scriptLoadPromise :Promise|null
Cancelable promise for script loading. Used to prevent callbacks when destroyed.
- Type
- Promise | null
- Source
- YouTube.js, line 71
private #state :Object
Local state mirror exposed via player state API.
- Type
- Object
- Source
- YouTube.js, line 77
private #timeLoop :Looper|null
Loop helper for synthetic timeupdate polling.
- Type
- Looper | null
- Source
- YouTube.js, line 83
private #progressLoop :Looper|null
Loop helper for synthetic progress polling.
- Type
- Looper | null
- Source
- YouTube.js, line 89
private #container :HTMLElement|null
Container element for the YouTube iframe.
- Type
- HTMLElement | null
- Source
- YouTube.js, line 95
private, static #STATE :Object
Mapping of YouTube IFrame API player states.
- Type
- Object
- Source
- YouTube.js, line 647
private, static #defaultState :Object
Default state object for the YouTube engine.
- Type
- Object
- Source
- YouTube.js, line 660
private, static #emptyRange :Object
Fallback empty TimeRanges-like object.
- Type
- Object
- Source
- YouTube.js, line 682
Methods
canPlay(metaData) → 'probably'|''
Checks if this engine can play the given media data, by checking if the source contains a valid YouTube video ID.
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
metaData |
Media~metaData |
The data to test.
|
- Returns
-
Indicates if stream can be played.
- Type 'probably' | ''
- Source
- YouTube.js, line 163
private #loadLib() → Promise<Object>
Loads YouTube IFrame API via CDN if not present. Uses scriptLoader for deduplication, wraps in custom Promise for API-ready callback.
- Returns
-
Cancelable promise that resolves with the YT namespace.
- Type Promise<Object>
- Source
- YouTube.js, line 175
private #load(metaData, optionsopt) → Promise<Media~metaData>
Loads media into the YouTube player.
| Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
metaData |
Media~metaData |
The media data to load. |
||||||||||||||||||||||||||||||||||||
options |
Object | optional |
Additional options.
|
- Returns
-
Resolves with current metadata once API is available.
- Type Promise<Media~metaData>
- Source
- YouTube.js, line 252
private #loadVideo(videoId, seek, play, volume, muted)
Cues a video and primes seek/volume/mute state before playback.
| Name | Type | Description |
|---|---|---|
videoId |
string |
Identifier of the YouTube video to load. |
seek |
number |
Start position in seconds for initial cue. |
play |
boolean |
Whether playback should start after cueing. |
volume |
number |
Initial volume fraction (0..1). |
muted |
boolean |
Whether audio starts muted. |
- Source
- YouTube.js, line 320
private #onLoaded()
Syncs metadata after the player signals it is cued and emits Media API events.
private #getMetaData() → Media~metaData
Returns the current metadata.
- Returns
-
The current metadata.
- Type Media~metaData
- Source
- YouTube.js, line 373
private #play()
Plays the media.
- Fires
- media/play
- Source
- YouTube.js, line 379
private #pause()
Pauses the media.
- Fires
- media/pause
- Source
- YouTube.js, line 392
private #loop(loop)
Sets the loop state.
| Name | Type | Description |
|---|---|---|
loop |
boolean |
Whether to loop. |
- Fires
- media/loop
- Source
- YouTube.js, line 405
private #playbackRate(rate)
Sets the playback rate.
| Name | Type | Description |
|---|---|---|
rate |
number |
The playback rate (0.25 to 2). |
- Fires
- media/ratechange
- Source
- YouTube.js, line 419
private #seek(time)
Seeks to a specific time.
| Name | Type | Description |
|---|---|---|
time |
number |
The time to seek to (in seconds). |
- Fires
- media/seeked
- Source
- YouTube.js, line 434
private #volume(volume)
Sets the volume.
| Name | Type | Description |
|---|---|---|
volume |
number |
The volume (0 to 1). |
- Fires
- media/volumechange
- Source
- YouTube.js, line 452
private #mute(mute)
Sets the mute state.
| Name | Type | Description |
|---|---|---|
mute |
boolean |
Whether to mute. |
- Fires
- media/volumechange
- Source
- YouTube.js, line 465
private #updateRanges()
Recomputes buffered/played ranges from the current player state.
- Source
- YouTube.js, line 477
private #onStateChange(event)
Maps YouTube player states to Media API events and timers.
| Name | Type | Description |
|---|---|---|
event |
Object |
State change payload from YT IFrame API. |
private #getIFrameElement() → HTMLIFrameElement|null
Returns the YouTube iframe element.
- Returns
-
The iframe element or null if not mounted.
- Type HTMLIFrameElement | null
- Source
- YouTube.js, line 553
async enable()
Enables the YouTube engine.
- Source
- YouTube.js, line 558
disable()
Disables the YouTube engine.
- Source
- YouTube.js, line 604
destroy()
This method removes all events, subscriptions and DOM nodes created by this component.
- Source
- YouTube.js, line 630
private, static #toRange(start, end) → Object
Creates a minimal TimeRanges-like object for a single range.
| Name | Type | Description |
|---|---|---|
start |
number |
Range start in seconds. |
end |
number |
Range end in seconds. |
- Returns
-
Range accessor.
- Type Object
- Source
- YouTube.js, line 694
private, static #extractVideoId(src) → string|null
Extracts a YouTube video id from a URL.
| Name | Type | Description |
|---|---|---|
src |
string |
Source URL. |
- Returns
-
Video id if found.
- Type string | null
- Source
- YouTube.js, line 711