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.
Classes
Members
-
static module:videojs~videojs.bindfunction
-
Deprecated reference to the
fn.bind_ function- Deprecated
- Deprecated and will be removed in 9.0. Please use native Function.prototype.bind instead.
- See:
-
fn.bind_
-
static module:videojs~videojs.browserObject
-
A reference to the
browser utility moduleas an object.- See:
-
static module:videojs~videojs.createTimeRangefunction
-
Deprecated reference to the
createTimeRanges function- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.time.createTimeRanges instead.
- See:
-
static module:videojs~videojs.createTimeRangesfunction
-
Deprecated reference to the
createTimeRanges function- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.time.createTimeRanges instead.
- See:
-
static module:videojs~videojs.defineLazyPropertyfunction
-
Deprecated reference to the
defineLazyProperty function- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.obj.defineLazyProperty instead.
- See:
-
static module:videojs~videojs.domObject
-
A reference to the
DOM utility moduleas an object.- See:
-
static module:videojs~videojs.fnObject
-
A reference to the
fn utility moduleas an object.- See:
-
static module:videojs~videojs.formatTimefunction
-
Deprecated reference to the
formatTime function- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.time.format instead.
- See:
-
static module:videojs~videojs.isCrossOriginfunction
-
Deprecated reference to the
Url.isCrossOrigin function- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.url.isCrossOrigin instead.
- See:
-
static module:videojs~videojs.logfunction
-
A reference to the
log utility moduleas an object.- See:
-
static module:videojs~videojs.mergeOptionsfunction
-
Deprecated reference to the
merge function- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.obj.merge instead.
- See:
-
static module:videojs~videojs.numObject
-
A reference to the
num utility moduleas an object.- See:
-
static module:videojs~videojs.objObject
-
A reference to the
obj utility moduleas an object.- See:
-
static module:videojs~videojs.optionsObject
-
The global options object. These are the settings that take effect if no overrides are specified when the player is created.
-
static module:videojs~videojs.parseUrlfunction
-
Deprecated reference to the
Url.parseUrl function- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.url.parseUrl instead.
- See:
-
static module:videojs~videojs.playersObject
-
Global enumeration of players.
The keys are the player IDs and the values are either the
Playerinstance ornullfor disposed players. -
static module:videojs~videojs.resetFormatTimefunction
-
Deprecated reference to the
resetFormatTime function- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.time.resetFormat instead.
- See:
-
static module:videojs~videojs.setFormatTimefunction
-
Deprecated reference to the
setFormatTime function- Deprecated
- Deprecated and will be removed in 9.0. Please use videojs.time.setFormat instead.
- See:
-
static module:videojs~videojs.strObject
-
A reference to the
str utility moduleas an object.- See:
-
str
-
static module:videojs~videojs.timeObject
-
A reference to the
time utility moduleas an object.- See:
-
static module:videojs~videojs.urlObject
-
A reference to the
URL utility moduleas an object.- See:
-
static module:videojs~videojs.VERSIONstring
-
Current Video.js version. Follows semantic versioning.
Methods
-
staticmodule:videojs~videojs.addLanguage(code, data){Object}
-
Adding languages so that they're available to all players. Example:
videojs.addLanguage('es', { 'Hello': 'Hola' });Name Type Description codestring The language code or dictionary property
dataObject The data values to be translated
Returns:
Type Description Object The resulting language dictionary object -
staticmodule:videojs~videojs.deregisterPlugin(name)
-
De-register a Video.js plugin.
Name Type Description namestring The name of the plugin to be de-registered. Must be a string that matches an existing plugin.
Throws:
Type When Error If an attempt is made to de-register the base plugin.
-
staticmodule:videojs~videojs.getAllPlayers(){Array}
-
Returns an array of all current players.
Returns:
Type Description Array An array of all players. The array will be in the order that Object.keysprovides, which could potentially vary between JavaScript engines. -
staticmodule:videojs~videojs.getComponent(name)
-
Get a
Componentbased on the name it was registered with.Name Type Description namestring The Name of the component to get.
Returns:
-
staticmodule:videojs~videojs.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 idstring | Element An HTML element -
<video>,<audio>, or<video-js>- or a string matching theidof such an element.Returns:
Type Description Player | undefined A player instance or undefinedif there is no player instance matching the argument. -
staticmodule:videojs~videojs.getPlayers(){Object}
-
Get an object with the currently created players, keyed by player ID
Returns:
Type Description Object The created players -
staticmodule:videojs~videojs.getPlugin(name)
-
Gets a plugin by name if it exists.
Name Type Description namestring The name of a plugin.
Returns:
-
staticmodule:videojs~videojs.getPlugins(names){Object|undefined}
-
Gets an object containing multiple Video.js plugins.
Name Type Description namesArray optional If provided, should be an array of plugin names. Defaults to all plugin names.
Returns:
Type Description Object | undefined An object containing plugin(s) associated with their name(s) or undefinedif no matching plugins exist). -
staticmodule:videojs~videojs.getPluginVersion(name){string}
-
Gets a plugin's version, if available
Name Type Description namestring The name of a plugin.
Returns:
Type Description string The plugin's version or an empty string. -
staticmodule:videojs~videojs.getTech(name){Tech|undefined}
-
Get a
Techfrom the shared list by name.Name Type Description namestring camelCaseorTitleCasename of the Tech to getReturns:
Type Description Tech | undefined The Techor undefined if there was no tech with the name requested. -
staticmodule:videojs~videojs.off(elem, type, fn)
-
Removes event listeners from an element
Name Type Description elemElement | Object Object to remove listeners from.
typestring | Array.<string> optional Type of listener to remove. Don't include to remove all events from element.
fnfunction optional Specific listener to remove. Don't include to remove listeners for an event type.
-
staticmodule:videojs~videojs.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 elemElement | Object Element or object to bind listeners to
typestring | Array.<string> Type of event to bind to.
fnfunction Event listener.
-
staticmodule:videojs~videojs.one(elem, type, fn)
-
Trigger a listener only once for an event.
Name Type Description elemElement | Object Element or object to bind to.
typestring | Array.<string> Name/type of event
fnEvent~EventListener Event listener function
-
staticmodule:videojs~videojs.plugin(name, plugin)
-
Deprecated method to register a plugin with Video.js
Name Type Description namestring The plugin name
plugin- Deprecated
- Deprecated and will be removed in 9.0. Use videojs.registerPlugin() instead.
Returns:
-
staticmodule:videojs~videojs.registerComponent(name, comp)
-
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 namestring The class name of the component
compReturns:
-
staticmodule:videojs~videojs.registerPlugin(name, plugin)
-
Register a Video.js plugin.
Name Type Description namestring The name of the plugin to be registered. Must be a string and must not match an existing plugin or a method on the
Playerprototype.pluginReturns:
-
staticmodule:videojs~videojs.registerTech(name, tech)
-
Registers a
Techinto a shared list for videojs.Name Type Description namestring Name of the
Techto register.techObject The
Techclass to register. -
staticmodule:videojs~videojs.trigger(elem, event, hash){boolean|undefined}
-
Trigger an event for an element
Name Type Description elemElement | Object Element to trigger an event on
eventEventTarget~Event | string A string (the type) or an event object with a type attribute
hashObject optional data hash to pass along with the event
Returns:
Type Description boolean | undefined Returns the opposite of defaultPreventedif default was prevented. Otherwise, returnsundefined -
staticmodule:videojs~videojs.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 typestring The MIME type to match or
"*"for all MIME types.middlewareMiddlewareFactory A middleware factory function that will be executed for matching types.
-
staticmodule:videojs~videojs.xhr(options){XMLHttpRequest|XDomainRequest}
-
A cross-browser XMLHttpRequest wrapper.
Name Type Description optionsObject Settings for the request.
Returns:
Type Description XMLHttpRequest | XDomainRequest The request object.