Constructor
new Data(player, parent, optionsopt)
Creates an instance of the Data component.
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
player |
Player |
Reference to the VisionPlayer instance. |
|||||||||
parent |
Player |
Reference to the parent instance. |
|||||||||
options |
Object | optional |
Additional options.
|
- Throws
-
If trying to disable this component.
Type Error
Members
private #config :Object
Contains configuration options for how the media is parsed and validated.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
skipInvalidItems
|
boolean | optional | false | Ignore (skip) invalid media items rather than throwing an error. |
skipInvalidRepresentations
|
boolean | optional | true | Ignore invalid representations instead of throwing errors for them. |
skipEmptyData
|
boolean | optional | false | Ignore empty media data (eg is |
disablePlayCheck
|
boolean | optional | false | Skip any play checks and trust the source to be playable. |
lenientPlayCheck
|
boolean | optional | false | Check only file extensions, but do not use |
lenientPlayCheckBlob
|
boolean | optional | true | Assume blob: URLs are valid without checking. |
preferredQuality
|
number | string | boolean | optional | Quality setting that should be preferred when loading new media, or |
|
preferredLanguage
|
string | boolean | optional | Language that should be preferred when loading new media, |
private #player :Player
private #data :Object
Contains the players' mediaData.
| Name | Type | Attributes | Description |
|---|---|---|---|
media
|
Array<Data~mediaItem> | Array of media items. |
|
currentMediaIndex
|
number | Index of the currently active media item. |
|
title
|
string | Object<string, string> | optional | Title of the playlist. |
titleSecondary
|
string | Object<string, string> | optional | Secondary title of the playlist. |
private #rootEle :HTMLElement
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.
private #setMediaDataTask :AsyncTask
Reference to the Async Task instance. Used to handle async tasks, which can be cancelled, resolved or rejected.
private #dataErrorTimeoutId :number
Timeout ID for data error publishing. Used to prevent race conditions when component is destroyed.
private #previousDataArg
The previous mediaData argument. Used for handling repeated calls to setMediaData. If two calls have the same mediaData, both will get the same promise. If the new call is different, the old one is cancelled.
Methods
private #getMediaData(selectoropt) → Data~mediaItem|Object|number|undefined
Depending on the selector, returns a specific media item (selector is a number representing the index in the media playlist), the entire data object (selector = 'all'), the current media item (selector = 'current') or the currently active index (selector = 'index').
| Name | Type | Attributes | Description |
|---|---|---|---|
selector |
number | 'all' | 'index' | optional |
Either a media based on numerical index, 'all' for all data, or 'index' for the current media index. |
- Returns
-
Returns one media item, the entire data object, the current media item, or the current numerical index, depending on the selector.
- Type Data~mediaItem | Object | number | undefined
- Source
- Data.js, line 131
private #setMediaData(mediaData, indexopt) → Promise
Assigns media data to the player instance. mediaData can be a valid data object or a string, in this case the player will either
- try to to load it as a media resource directly (if the extension matches a known type) or
- try to load it as a mediaData object in JSON format.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
mediaData |
Data~mediaItem | string |
Can be either a string representing an url or a media object. |
||
index |
number | optional | 0 |
The index of the media item to switch to. |
- Fires
- data/parsed
- data/nomedia
- Returns
-
A promise that resolves with the loaded and parsed data or rejects when loading or parsing failed.
- Type Promise
- Source
- Data.js, line 154
private #setMediaIndex(index, optionsopt) → Promise
Switches playback to another media item, with index representing the position of the media to switch to in the internal playlist.
Additional options can influence switching behavior in the Media component, like trying to restore the previous seek position (rememberState)
or controlling if and how the media is played after switching (ignoreAutoplay, play).
| Name | Type | Attributes | Description |
|---|---|---|---|
index |
number |
The index of the media item to switch to. |
|
options |
Media~mediaLoadOptions | optional |
Optional config to set switch behavior. |
- Fires
- data/ready
- Returns
-
A promise that resolves with the loaded metadata of the switched item data or rejects when loading failed.
- Type Promise
- Source
- Data.js, line 243
private #getPreferredMetaData(optionsopt, mediaItemopt) → Media~metaData
Returns the best matching media variant, considering the user's language and quality preferences. Falls back to the closest possible match if an exact match isn't found. In this case, language preferences have priority over quality preferences.
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | optional |
Optional preferences.
|
||||||||||||
mediaItem |
Data~mediaItem | optional |
Media item to search for, defaults to current active item. |
- Returns
-
Metadata for a matching media object, or 'false' if nothing suitable was found.
- Type Media~metaData
- Source
- Data.js, line 284
async, private #loadMediaData(url) → Promise<Data~mediaItem>
Loads media data definition from a given URL into the player.
| Name | Type | Description |
|---|---|---|
url |
string |
The URL pointing to a JSON file describing the media data. |
- Returns
-
A promise that resolves to the loaded media data.
- Type Promise<Data~mediaItem>
- Source
- Data.js, line 376
async, private #parseMediaDataItem(mediaItem) → Promise<Data~mediaItem>
Parses a single media item (either as URL or object) and returns a normalized media data structure.
This includes resolving variants & representations, validating MIME types, applying quality/height heuristics,
and optionally loading remote JSON if the input is a URL pointing to a JSON file.
This method is used internally by #setMediaData() and supports both individual items and full playlists.
| Name | Type | Description |
|---|---|---|
mediaItem |
string | Data~mediaItem |
The media data to parse, either as object or URL string. |
- Returns
-
A Promise resolving to a valid mediaItem structure.
- Type Promise<Data~mediaItem>
- Throws
-
If parsing fails or no playable source is found.
Type Error - Source
- Data.js, line 400
private #addPlayableMetaData(metaDataArg, pushArrayopt, mediaItemopt) → Media~metaData|false
This helper function searches a source object for a playable source, i.e. A source which has a mime type which at least results in a 'maybe' using the engines 'canPlay' test method. Representations which return a 'probably' are preferred. If no mime type is provided, the method tries to guess it from the source path file ext.
| Name | Type | Attributes | Description |
|---|---|---|---|
metaDataArg |
Media~metaData |
The metaData object to search. |
|
pushArray |
Array<Media~metaData> | optional |
If provided, the playable metaData item is pushed there on success. |
mediaItem |
Data~mediaItem | optional |
If provided, the detected mediaType is assigned to it. |
- Returns
-
The playable metaData if found, otherwise false.
- Type Media~metaData | false
- Throws
-
Throws various Errors when parsing fails.
Type Error - Source
- Data.js, line 544
private #dataError(messageOrKey, erroropt)
This method should be called when a 'data error' occurs. In contrast to a 'media error' which usually indicates problems with playing back certain media (for example, due to network problems or decoding errors), a data error usually means that the player - or some component - wasn't able to correctly and completely parse the data it was provided. A typical case would be some essential things missing from the media data, like no src. Also publishes an appropriate event, so other components can for example display an error message to the user.
| Name | Type | Attributes | Description |
|---|---|---|---|
messageOrKey |
string |
The message text or translate key. |
|
error |
Error | optional |
Optional error object. |
- Fires
- data/error
- Source
- Data.js, line 646
destroy()
This is the cleanup method which should be called when removing the player. It is strongly recommended to do so to prevent memory leaks and possible other unwanted side effects.
Type Definitions
mediaItem
The mediaItem is a representation of a single media data item.
| Name | Type | Attributes | Description |
|---|---|---|---|
title
|
string | Object<string, string> | optional | Title of the media item (can be multilingual). |
titleSecondary
|
string | Object<string, string> | optional | Secondary title of the media player in multiple languages. |
variants
|
Array<Data~mediaItem_variants> | List of available video variants. |
|
text
|
Array<Data~mediaItem_text> | optional | List of subtitle tracks. |
overlays
|
Array<Data~mediaItem_overlay> | optional | List of overlays displayed in the player. |
chapters
|
Array<Data~mediaItem_chapter> | optional | List of video chapters. |
thumbnails
|
Data~mediaItem_thumbnail | optional | The thumbnail representation of this media item. |
mediaItem_variants
The variants item is a representation of a single variant data item.
| Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
language
|
string | Language of the variant. |
|||||||||||||||||||||||||||||||||
default
|
boolean | optional | Whether this variant is marked as default. |
||||||||||||||||||||||||||||||||
representations
|
Array<Object> | Available representations for this variant.
|
mediaItem_overlay
The overlaysItem is a representation of a single overlay data item.
| Name | Type | Attributes | Description |
|---|---|---|---|
type
|
string | Type of overlay (e.g., 'poster', 'image'). |
|
src
|
string | Source URL of the overlay. |
|
className
|
string | optional | Optional CSS class for styling the overlay. |
alt
|
string | optional | Alternative text for the overlay image. |
placement
|
string | optional | Placement of the overlay on the screen. |
margin
|
number | optional | Margin around the overlay. |
cueIn
|
number | optional | Timestamp (in seconds) when the overlay appears. |
cueOut
|
number | optional | Timestamp (in seconds) when the overlay disappears. |
mediaItem_text
The textItem is a representation of a single text data item.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
type
|
string | optional | 'subtitles' | Type of subtitle track (e.g., 'subtitles', 'captions' etc). |
language
|
string | Language of the subtitle track. |
||
src
|
string | Source URL of the subtitle file. |
||
default
|
boolean | optional | Whether this is the default subtitle track. |
mediaItem_chapter
The chapterItem is a representation of a single chapter data item.
| Name | Type | Description |
|---|---|---|
title
|
string | Object<string, string> | Chapter title (can be multilingual). |
start
|
number | Start time of the chapter in seconds. |
mediaItem_thumbnail
The thumbnailsItem is a representation of a single thumbnail data item.
| Name | Type | Attributes | Description |
|---|---|---|---|
src
|
string | Object | Thumbnail image source(s), either direct src or object for multiple languages. |
|
gridX
|
number | Number of thumbnail columns. |
|
gridY
|
number | Number of thumbnail rows. |
|
timeDelta
|
number | Time difference between thumbnails. |
|
timeDeltaHigh
|
number | optional | High-resolution thumbnail time difference. |
Events
data/parsed
Fired when the player data was parsed and is available for further consumption.
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object |
Reference to the data store.
|
- Listeners
- Playlist#onDataParsed
- Source
- Data.js, line 746
data/ready
Fired when a media item has been assigned (but media is not fully loaded yet).
| Name | Type | Description |
|---|---|---|
mediaItem |
Data~mediaItem |
The new media item data. |
- Listeners
- FullScreen#onDataReady
- PictureInPicture#onDataReady
- Play#onDataReady
- Volume#onVolumeUpdate
- Media#onDataReady
- Media#onStallEnd
- Playlist#onDataReady
- Language#onDataReady
- Quality#onDataReady
- VideoControls#onMediaReady
- Dash#removeDash
- Hls#removeHls
- Subtitles#onDataReady
- Chapters#onDataReady
- Overlays#onDataReady
- Thumbnails#onDataReady
- Title#onDataReady
- UI#onDataReady
- AudioChain#disconnectVideo
- AnalyserAudio#onDataReady
- AnalyserVideo#onDataReady
- VisualizerAmbient#onDataReady
- Source
- Data.js, line 756
data/source
Fired when a media source has been selected, but before the actual load.
| Name | Type | Description |
|---|---|---|
metaData |
Media~metaData |
The new media metadata. |
- Listeners
- Language#onDataSource
- Quality#onDataSource
- Source
- Data.js, line 762
data/error
Fired when a data related error occurs (for example a parsing error due to wrong media data format).
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
msgObj |
Object |
The data error message object.
|
- Listeners
- Notifications#onDataError
- Source
- Data.js, line 768
data/nomedia
Fired when no usable media data is found.