videojs~ videojs

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.

Parameters:
NameTypeAttributesDescription
idstring | Element

Video element or video element ID.

optionsObject<optional>

Options object for providing settings. See: Options Guide.

readyReadyCallback<optional>

A function to be called when the Player and Tech are ready.

Returns:

The videojs() function returns a Player instance.

Type: 
Player

Classes

AudioTrack
EventTarget
TextTrack
VideoTrack

Members

bind :function

Deprecated reference to the fn.bind_ function

Type:
  • function
Deprecated
  • Deprecated and will be removed in 9.0. Please use native Function.prototype.bind instead.
See
  • fn.bind_

browser :Object

A reference to the browser utility module as an object.

Type:
  • Object

createTimeRange :function

Deprecated reference to the createTimeRanges function

Type:
  • function
Deprecated
  • Deprecated and will be removed in 9.0. Please use videojs.time.createTimeRanges instead.

createTimeRanges :function

Deprecated reference to the createTimeRanges function

Type:
  • function
Deprecated
  • Deprecated and will be removed in 9.0. Please use videojs.time.createTimeRanges instead.

defineLazyProperty :function

Deprecated reference to the defineLazyProperty function

Type:
  • function
Deprecated
  • Deprecated and will be removed in 9.0. Please use videojs.obj.defineLazyProperty instead.

dom :Object

A reference to the DOM utility module as an object.

Type:
  • Object
See

fn :Object

A reference to the fn utility module as an object.

Type:
  • Object
See

formatTime :function

Deprecated reference to the formatTime function

Type:
  • function
Deprecated
  • Deprecated and will be removed in 9.0. Please use videojs.time.format instead.

isCrossOrigin :function

Deprecated reference to the Url.isCrossOrigin function

Type:
  • function
Deprecated
  • Deprecated and will be removed in 9.0. Please use videojs.url.isCrossOrigin instead.

log :function

A reference to the log utility module as an object.

Type:
  • function
See

mergeOptions :function

Deprecated reference to the merge function

Type:
  • function
Deprecated
  • Deprecated and will be removed in 9.0. Please use videojs.obj.merge instead.

num :Object

A reference to the num utility module as an object.

Type:
  • Object
See

obj :Object

A reference to the obj utility module as an object.

Type:
  • Object
See

options :Object

The global options object. These are the settings that take effect if no overrides are specified when the player is created.

Type:
  • Object

parseUrl :function

Deprecated reference to the Url.parseUrl function

Type:
  • function
Deprecated
  • Deprecated and will be removed in 9.0. Please use videojs.url.parseUrl instead.

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.

Type:
  • Object

resetFormatTime :function

Deprecated reference to the resetFormatTime function

Type:
  • function
Deprecated
  • Deprecated and will be removed in 9.0. Please use videojs.time.resetFormat instead.

setFormatTime :function

Deprecated reference to the setFormatTime function

Type:
  • function
Deprecated
  • Deprecated and will be removed in 9.0. Please use videojs.time.setFormat instead.

str :Object

A reference to the str utility module as an object.

Type:
  • Object
See
  • str

time :Object

A reference to the time utility module as an object.

Type:
  • Object
See

url :Object

A reference to the URL utility module as an object.

Type:
  • Object
See

VERSION :string

Current Video.js version. Follows semantic versioning.

Type:
  • string

Methods

addLanguage(code, data) → {Object}

Adding languages so that they're available to all players. Example: videojs.addLanguage('es', { 'Hello': 'Hola' });

Parameters:
NameTypeDescription
codestring

The language code or dictionary property

dataObject

The data values to be translated

Returns:

The resulting language dictionary object

Type: 
Object

deregisterPlugin(name)

De-register a Video.js plugin.

Parameters:
NameTypeDescription
namestring

The name of the plugin to be de-registered. Must be a string that matches an existing plugin.

Throws:

If an attempt is made to de-register the base plugin.

Type
Error

getAllPlayers() → {Array}

Returns an array of all current players.

Returns:

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

getComponent(name) → {Component}

Get a Component based on the name it was registered with.

Parameters:
NameTypeDescription
namestring

The Name of the component to get.

Returns:

The Component that got registered under the given name.

Type: 
Component

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.

Parameters:
NameTypeDescription
idstring | Element

An HTML element - <video>, <audio>, or <videojs> - or a string matching the id of such an element.

Returns:

A player instance or undefined if there is no player instance matching the argument.

Type: 
Player | undefined

getPlayers() → {Object}

Get an object with the currently created players, keyed by player ID

Returns:

The created players

Type: 
Object

getPlugin(name) → {Class.<Plugin>|function|undefined}

Gets a plugin by name if it exists.

Parameters:
NameTypeDescription
namestring

The name of a plugin.

Returns:

The plugin (or undefined).

Type: 
Class.<Plugin> | function | undefined

getPlugins(namesopt) → {Object|undefined}

Gets an object containing multiple Video.js plugins.

Parameters:
NameTypeAttributesDescription
namesArray<optional>

If provided, should be an array of plugin names. Defaults to all plugin names.

Returns:

An object containing plugin(s) associated with their name(s) or undefined if no matching plugins exist).

Type: 
Object | undefined

getPluginVersion(name) → {string}

Gets a plugin's version, if available

Parameters:
NameTypeDescription
namestring

The name of a plugin.

Returns:

The plugin's version or an empty string.

Type: 
string

getTech(name) → {Tech|undefined}

Get a Tech from the shared list by name.

Parameters:
NameTypeDescription
namestring

camelCase or TitleCase name of the Tech to get

Returns:

The Tech or undefined if there was no tech with the name requested.

Type: 
Tech | undefined

off(elem, typeopt, fnopt)

Removes event listeners from an element

Parameters:
NameTypeAttributesDescription
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.

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.

Parameters:
NameTypeDescription
elemElement | Object

Element or object to bind listeners to

typestring | Array.<string>

Type of event to bind to.

fnfunction

Event listener.

one(elem, type, fn)

Trigger a listener only once for an event.

Parameters:
NameTypeDescription
elemElement | Object

Element or object to bind to.

typestring | Array.<string>

Name/type of event

fnEvent~EventListener

Event listener function

plugin(name, plugin)

Deprecated method to register a plugin with Video.js

Parameters:
NameTypeDescription
namestring

The plugin name

pluginPlugin | function

The plugin sub-class or function

Deprecated
  • Deprecated and will be removed in 9.0. Use videojs.registerPlugin() instead.

registerComponent(name, comp) → {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());

Parameters:
NameTypeDescription
namestring

The class name of the component

compComponent

The component class

Returns:

The newly registered component

Type: 
Component

registerPlugin(name, plugin) → {Class.<Plugin>|function}

Register a Video.js plugin.

Parameters:
NameTypeDescription
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 Player prototype.

pluginClass.<Plugin> | function

A sub-class of Plugin or a function for basic plugins.

Returns:

For advanced plugins, a factory function for that plugin. For basic plugins, a wrapper function that initializes the plugin.

Type: 
Class.<Plugin> | function

registerTech(name, tech)

Registers a Tech into a shared list for videojs.

Parameters:
NameTypeDescription
namestring

Name of the Tech to register.

techObject

The Tech class to register.

trigger(elem, event, hashopt) → {boolean|undefined}

Trigger an event for an element

Parameters:
NameTypeAttributesDescription
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:

Returns the opposite of defaultPrevented if default was prevented. Otherwise, returns undefined

Type: 
boolean | undefined

use(type, middleware)

Define a middleware that the player should use by way of a factory function that returns a middleware object.

Parameters:
NameTypeDescription
typestring

The MIME type to match or "*" for all MIME types.

middlewareMiddlewareFactory

A middleware factory function that will be executed for matching types.

xhr(options) → {XMLHttpRequest|XDomainRequest}

A cross-browser XMLHttpRequest wrapper.

Parameters:
NameTypeDescription
optionsObject

Settings for the request.

Returns:

The request object.

Type: 
XMLHttpRequest | XDomainRequest