videojs(id, optionsopt, readyopt) → {Player}
The videojs()
function doubles as the main function for users to create a Player instance as well as the main library namespace.
It can also be used as a getter for a pre-existing Player instance. However, we strongly recommend using videojs.getPlayer()
for this purpose because it avoids any potential for unintended initialization.
Due to limitations of our JSDoc template, we cannot properly document this as both a function and a namespace, so its function signature is documented here.
Arguments
id
string|Element, required
Video element or video element ID.
options
Object, optional
Options object for providing settings. See: Options Guide.
ready
Component~ReadyCallback, optional
A function to be called when the Player and Tech are ready.
Return Value
The videojs()
function returns a Player instance.
Name | Type | Attributes | Description |
---|---|---|---|
id | string | | Video element or video element ID. | |
options | Object | <optional> | Options object for providing settings. See: Options Guide. |
ready | ReadyCallback | <optional> |
Classes
Members
(static) bind :function
Deprecated reference to the fn.bind_ function
- function
- Deprecated
- Deprecated and will be removed in 9.0. Please use native Function.prototype.bind instead.
- See
- fn.bind_
(static) browser :Object
A reference to the browser utility module as an object.
- Object
- See
(static) createTimeRange :function
Deprecated reference to the createTimeRanges function
- function
- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.time.createTimeRanges instead.
(static) createTimeRanges :function
Deprecated reference to the createTimeRanges function
- function
- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.time.createTimeRanges instead.
(static) defineLazyProperty :function
Deprecated reference to the defineLazyProperty function
- function
- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.obj.defineLazyProperty instead.
(static) dom :Object
A reference to the DOM utility module as an object.
- Object
- See
(static) fn :Object
A reference to the fn utility module as an object.
- Object
- See
(static) formatTime :function
Deprecated reference to the formatTime function
- function
- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.time.format instead.
- See
(static) isCrossOrigin :function
Deprecated reference to the Url.isCrossOrigin function
- function
- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.url.isCrossOrigin instead.
(static) log :function
A reference to the log utility module as an object.
- function
- See
(static) mergeOptions :function
Deprecated reference to the merge function
- function
- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.obj.merge instead.
- See
(static) num :Object
A reference to the num utility module as an object.
- Object
- See
(static) obj :Object
A reference to the obj utility module as an object.
- Object
- See
(static) options :Object
The global options object. These are the settings that take effect if no overrides are specified when the player is created.
- Object
(static) parseUrl :function
Deprecated reference to the Url.parseUrl function
- function
- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.url.parseUrl instead.
- See
(static) players :Object
Global enumeration of players.
The keys are the player IDs and the values are either the Player instance or null
for disposed players.
- Object
(static) resetFormatTime :function
Deprecated reference to the resetFormatTime function
- function
- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.time.resetFormat instead.
(static) setFormatTime :function
Deprecated reference to the setFormatTime function
- function
- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.time.setFormat instead.
(static) str :Object
A reference to the str utility module as an object.
- Object
- See
- str
(static) time :Object
A reference to the time utility module as an object.
- Object
- See
(static) url :Object
A reference to the URL utility module as an object.
- Object
- See
(static) VERSION :string
Current Video.js version. Follows semantic versioning.
- string
Methods
(static) addLanguage(code, data) → {Object}
Adding languages so that they're available to all players. Example: videojs.addLanguage('es', { 'Hello': 'Hola' });
Name | Type | Description |
---|---|---|
code | string | The language code or dictionary property |
data | Object | The data values to be translated |
The resulting language dictionary object
- Type:
- Object
(static) deregisterPlugin(name)
De-register a Video.js plugin.
Name | Type | Description |
---|---|---|
name | string | The name of the plugin to be de-registered. Must be a string that matches an existing plugin. |
If an attempt is made to de-register the base plugin.
- Type
- Error
(static) getAllPlayers() → {Array}
Returns an array of all current players.
An array of all players. The array will be in the order that Object.keys
provides, which could potentially vary between JavaScript engines.
- Type:
- Array
(static) getComponent(name) → {Class.<Component>}
Get a Component
based on the name it was registered with.
Name | Type | Description |
---|---|---|
name | string | The Name of the component to get. |
- Source
The Component
that got registered under the given name.
- Type:
- Class.<Component>
(static) getPlayer(id) → {Player|undefined}
Get a single player based on an ID or DOM element.
This is useful if you want to check if an element or ID has an associated Video.js player, but not create one if it doesn't.
Name | Type | Description |
---|---|---|
id | string | | An HTML element - |
A player instance or undefined
if there is no player instance matching the argument.
- Type:
- Player |
undefined
(static) getPlayers() → {Object}
Get an object with the currently created players, keyed by player ID
The created players
- Type:
- Object
(static) getPlugin(name) → {Class.<Plugin>|function|undefined}
Gets a plugin by name if it exists.
Name | Type | Description |
---|---|---|
name | string | The name of a plugin. |
The plugin (or undefined
).
- Type:
- Class.<Plugin> |
function | undefined
(static) getPlugins(namesopt) → {Object|undefined}
Gets an object containing multiple Video.js plugins.
Name | Type | Attributes | Description |
---|---|---|---|
names | Array | <optional> | If provided, should be an array of plugin names. Defaults to all plugin names. |
An object containing plugin(s) associated with their name(s) or undefined
if no matching plugins exist).
- Type:
- Object |
undefined
(static) getPluginVersion(name) → {string}
Gets a plugin's version, if available
Name | Type | Description |
---|---|---|
name | string | The name of a plugin. |
The plugin's version or an empty string.
- Type:
- string
(static) getTech(name) → {Tech|undefined}
Get a Tech
from the shared list by name.
Name | Type | Description |
---|---|---|
name | string |
|
- Source
The Tech
or undefined if there was no tech with the name requested.
- Type:
- Tech |
undefined
(static) off(elem, typeopt, fnopt)
Removes event listeners from an element
Name | Type | Attributes | Description |
---|---|---|---|
elem | Element | | Object to remove listeners from. | |
type | string | | <optional> | Type of listener to remove. Don't include to remove all events from element. |
fn | function | <optional> | Specific listener to remove. Don't include to remove listeners for an event type. |
- Source
(static) on(elem, type, fn)
Add an event listener to element It stores the handler function in a separate cache object and adds a generic handler to the element's event, along with a unique id (guid) to the element.
Name | Type | Description |
---|---|---|
elem | Element | | Element or object to bind listeners to |
type | string | | Type of event to bind to. |
fn | function | Event listener. |
- Source
(static) one(elem, type, fn)
Trigger a listener only once for an event.
Name | Type | Description |
---|---|---|
elem | Element | | Element or object to bind to. |
type | string | | Name/type of event |
fn | Event~EventListener | Event listener function |
- Source
(static) plugin(name, plugin) → {Class.<Plugin>|function}
Deprecated method to register a plugin with Video.js
Name | Type | Description |
---|---|---|
name | string | The plugin name |
plugin | Class.<Plugin> | | The plugin sub-class or function |
- Deprecated
- Deprecated and will be removed in 9.0. Use videojs.registerPlugin() instead.
- Type:
- Class.<Plugin> |
function
(static) registerComponent(name, comp) → {Class.<Component>}
Register a component so it can referred to by name. Used when adding to other components, either through addChild component.addChild('myComponent')
or through default children options { children: ['myComponent'] }
.
NOTE: You could also just initialize the component before adding.
component.addChild(new MyComponent());
Name | Type | Description |
---|---|---|
name | string | The class name of the component |
comp | Class.<Component> | The component class |
The newly registered component
- Type:
- Class.<Component>
(static) registerPlugin(name, plugin) → {Class.<Plugin>|function}
Register a Video.js plugin.
Name | Type | Description |
---|---|---|
name | string | The name of the plugin to be registered. Must be a string and must not match an existing plugin or a method on the |
plugin | Class.<Plugin> | | A sub-class of |
For advanced plugins, a factory function for that plugin. For basic plugins, a wrapper function that initializes the plugin.
- Type:
- Class.<Plugin> |
function
(static) registerTech(name, tech)
Registers a Tech
into a shared list for videojs.
Name | Type | Description |
---|---|---|
name | string | Name of the |
tech | Object | The |
- Source
(static) trigger(elem, event, hashopt) → {boolean|undefined}
Trigger an event for an element
Name | Type | Attributes | Description |
---|---|---|---|
elem | Element | | Element to trigger an event on | |
event | EventTarget~Event | | A string (the type) or an event object with a type attribute | |
hash | Object | <optional> | data hash to pass along with the event |
- Source
Returns the opposite of defaultPrevented
if default was prevented. Otherwise, returns undefined
- Type:
- boolean |
undefined
(static) use(type, middleware)
Define a middleware that the player should use by way of a factory function that returns a middleware object.
Name | Type | Description |
---|---|---|
type | string | The MIME type to match or |
middleware | MiddlewareFactory | A middleware factory function that will be executed for matching types. |
- Source
(static) xhr(options) → {XMLHttpRequest|XDomainRequest}
A cross-browser XMLHttpRequest wrapper.
Name | Type | Description |
---|---|---|
options | Object | Settings for the request. |
The request object.
- Type:
- XMLHttpRequest |
XDomainRequest