- Version
- 2.0.0
- License
- MIT
- Requires
- object
- DomSmith
- scriptLoader
- Source
- ChromeCast.js, line 30
Constructor
new ChromeCast(player, parent, optionsopt)
Creates an instance of the ChromeCast component.
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
player |
Player |
Reference to the main VisionPlayer instance. |
|||||||||
parent |
Controller |
Reference to the parent instance. |
|||||||||
options |
Object | optional |
Additional options.
|
Members
private #config :Object
Configuration for the ChromeCast component.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
showControllerButton
|
boolean | optional | true | If |
showMenuButton
|
boolean | optional | true | If |
lazyLoadLib
|
boolean | optional | true | If |
- Type
- Object
- Source
- ChromeCast.js, line 39
private #player :Player
Reference to the main player instance.
- Type
- Player
- Source
- ChromeCast.js, line 49
private #parent :Popup
Reference to the settings menu element.
- Type
- Popup
- Source
- ChromeCast.js, line 55
private #subscriptions :Array<number>
Holds tokens of subscriptions to player events, for later unsubscribe.
- Type
- Array<number>
- Source
- ChromeCast.js, line 61
private #apiKey :symbol
Secret key only known to the player instance and initialized components. Used to be able to restrict access to API methods in conjunction with secure mode.
- Type
- symbol
- Source
- ChromeCast.js, line 68
private #backdrop :DomSmith
DomSmith instance for the Cast backdrop.
- Type
- DomSmith
- Source
- ChromeCast.js, line 74
private #buttonMenu :DomSmith
private #buttonController :DomSmith
private #remote :Object
Status information of the remote cast device.
| Name | Type | Attributes | Description |
|---|---|---|---|
state
|
string | Current player state (e.g., 'PLAYING', 'PAUSED', 'BUFFERING'). |
|
duration
|
number | Duration of the media in seconds. |
|
currentTime
|
number | Current playback position in seconds. |
|
playbackRate
|
number | Current playback rate (1.0 = normal speed). |
|
connected
|
boolean | Whether a cast session is currently active. |
|
paused
|
boolean | Whether playback is currently paused. |
|
activeTextTrack
|
number | Index of the currently active subtitle track (-1 if none). |
|
seekTo
|
number | null | Target time for seeking (null if no seek is pending). |
|
sessionState
|
string | optional | Current session state ('SESSION_STARTED', 'SESSION_RESUMED', 'SESSION_ENDED'). |
error
|
string | optional | Error message if an error occurred during casting. |
noIdleEvent
|
boolean | optional | Flag to prevent idle events during media loading. |
fontSize
|
string | optional | Font size for subtitles ('small', 'normal', 'big'). |
- Type
- Object
- Source
- ChromeCast.js, line 104
private #metaData :Media~metaData
Holds metadata information provided by media.load and loaded metadata.
- Type
- Media~metaData
- Source
- ChromeCast.js, line 119
private #castContext :Object
Instance of the Cast context.
- Type
- Object
- Source
- ChromeCast.js, line 125
private #castPlayer :Object
RemotePlayer instance for controlling the Cast device.
- Type
- Object
- Source
- ChromeCast.js, line 131
private #castPlayerController :Object
RemotePlayerController for monitoring changes to the RemotePlayer.
- Type
- Object
- Source
- ChromeCast.js, line 137
private #castSession :Object
Cast session instance.
- Type
- Object
- Source
- ChromeCast.js, line 143
private #isSupported :boolean
Flag indicating if currently active media is supported for casting.
- Type
- boolean
- Source
- ChromeCast.js, line 149
Methods
canPlay(metaData) → string
Checks if the current media source is supported for casting.
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
metaData |
Object |
The media metadata.
|
- Returns
-
'maybe' if the media source is supported, otherwise ''.
- Type string
- Source
- ChromeCast.js, line 292
private #onMediaReady(src)
Checks if the current media source is supported for casting and enables or disables buttons accordingly.
| Name | Type | Description |
|---|---|---|
src |
string |
The current media source. |
- Listens
- media/ready
- Source
- ChromeCast.js, line 319
async, private #addScripts()
Load Cast API Scripts from Google. This is only done after the user clicks the cast button. Uses the centralized scriptLoader utility for deduplication and reliability.
- Source
- ChromeCast.js, line 329
private #onAvailable()
Initializes the Cast context and sets up necessary event listeners.
- Source
- ChromeCast.js, line 366
private #toggleCasting()
Toggles casting on or off based on the current status. In addition the google cast code is loaded if invoked for the first time.
- Source
- ChromeCast.js, line 390
private #onTogglePlay()
Toggles playback (play/pause) of the cast media. Updates the backdrop button text accordingly.
- Source
- ChromeCast.js, line 406
async, private #startCasting() → void
Starts casting to a Chromecast device.
- Fires
- notification
- Returns
-
Returns when cast session has failed.
- Type void
- Source
- ChromeCast.js, line 423
private #generateRequest(sourceopt) → Object
Generates a media load request for casting. Also tries to include title, poster image and subtitles, if available.
| Name | Type | Attributes | Description |
|---|---|---|---|
source |
Object | optional |
The current media source. |
- Returns
-
The generated load request.
- Type Object
- Source
- ChromeCast.js, line 479
private #stopCasting()
Stops casting and restores the player to its original state.
- Source
- ChromeCast.js, line 548
private #castStopped()
Handles the stopping of casting. Restores the player to its original state and switches back to the video engine.
- Fires
- chromecast/stop
- Source
- ChromeCast.js, line 566
private #load(source, options)
Loads a media file into the Chromecast player.
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
source |
Object |
The media source. |
||||||
options |
Object |
The options for the load.
|
- Listens
- media/load
- Source
- ChromeCast.js, line 603
private #seek(val)
Seeks to a specific time position in the cast media.
| Name | Type | Description |
|---|---|---|
val |
number |
The target time in seconds. |
- Source
- ChromeCast.js, line 639
private #play()
Starts playback of the cast media.
- Fires
- media/play
- Source
- ChromeCast.js, line 648
private #pause()
Pauses playback of the cast media.
- Fires
- media/pause
- Source
- ChromeCast.js, line 658
private #loop(doLoop)
Disables or enables looping.
| Name | Type | Description |
|---|---|---|
doLoop |
boolean |
If |
- Fires
- media/loop
- Source
- ChromeCast.js, line 669
private #volume(val)
Sets the volume level for the cast media.
| Name | Type | Description |
|---|---|---|
val |
number |
Volume level between 0 and 1. |
- Fires
- media/volumechange
- Source
- ChromeCast.js, line 681
private #mute()
Toggles mute state of the cast media.
- Source
- ChromeCast.js, line 690
private #getMetaData() → Media~metaData
Returns a copy of the current media metadata.
- Returns
-
Object with current metadata.
- Type Media~metaData
- Source
- ChromeCast.js, line 700
private #getMediaElement(apiKey) → HTMLElement
Used by components to retrieve the video element.
| Name | Type | Description |
|---|---|---|
apiKey |
symbol |
Token needed to grant access in secure mode. |
- Returns
-
The element designated by the component as attachable container.
- Type HTMLElement
- Throws
-
If safe mode access was denied.
Type Error - Source
- ChromeCast.js, line 708
private #onCastEvent(event)
Handles cast events.
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
event |
Object |
The cast event from the google lib.
|
private #onSessionEvent(event)
Handles session events from the Cast context. Updates the remote session state based on the event type.
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
event |
Object |
Session event from the google lib.
|
- Source
- ChromeCast.js, line 841
private #onSubtitleChange(event)
Handles changes to subtitles.
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
event |
Object |
Subtitle change event info.
|
- Listens
- subtitles/selected
- Source
- ChromeCast.js, line 864
private #onFontChange(size)
Handles changes to the subtitle font size.
| Name | Type | Description |
|---|---|---|
size |
string |
The new font size ('small', 'normal', 'big'). |
- Listens
- subtitles/fontsize
- Source
- ChromeCast.js, line 884
private #onPlaybackRateChange(rate)
Handles changes to the playback rate.
| Name | Type | Description |
|---|---|---|
rate |
number |
The new playback rate. |
- Listens
- media/ratechange
- Source
- ChromeCast.js, line 907
private #updateButtonVisibility()
Enables the play button functionality. This method listens to canplay events in order to restore a usable state again when the player recovered from a media error (for example by loading another file).
- Listens
- media/canplay
- Source
- ChromeCast.js, line 932
private #hideButton()
Hides the Chromecast button when casting is unavailable.
- Listens
- media/error
- data/nomedia
- Source
- ChromeCast.js, line 948
enable()
Enables the Chromecast component. Subscribes to player events and sets the media state.
- Source
- ChromeCast.js, line 959
disable()
Disables the Chromecast component. Removes all events and subscriptions created by this component.
- Source
- ChromeCast.js, line 982
destroy()
Removes all events, subscriptions, and DOM nodes created by this component.
- Source
- ChromeCast.js, line 1007
Events
chromecast/start
This event is fired when chromecast was started.
- Listeners
- VisualizerAmbient#stopLoop
- Source
- ChromeCast.js, line 1029
chromecast/stop
This event is fired when chromecast was stopped.
- Listeners
- VisualizerAmbient#startLoop
- Source
- ChromeCast.js, line 1034