- Arguments
- Return Value
- Classes
- Members
- Methods
- static addLanguage(code, data) → {Object
- static bind(context, fn, uidopt) → {function}
- static computedStyle(el, prop)
- static createTimeRange(start, end)
- static createTimeRanges(start, end)
- static deregisterPlugin(name)
- static extend(superClass, subClassMethodsopt) → {function}
- static formatTime(seconds, guide) → {string}
- static getAllPlayers() → {Array}
- static getComponent(name) → { Component }
- static getPlayer(id) → { Player |undefined}
- static getPlayers() → {Object}
- static getPlugin(name) → {function|undefined}
- static getPlugins(namesopt) → {Object|undefined}
- static getPluginVersion(name) → {string}
- static getTech(name) → { Tech |undefined}
- static hook(type, The)
- static hookOnce(type, The)
- static hooks(type, fnopt) → {Array}
- static isCrossOrigin(url, winLocopt) → {boolean}
- static mergeOptions(…sources) → {Object}
- static off(elem, typeopt, fnopt)
- static on(elem, type, fn)
- static one(elem, type, fn)
- static parseUrl(url) → {url:URLObject}
- static plugin(name, plugin)
- static registerComponent(name, comp) → { Component }
- static registerPlugin(name, plugin) → {function}
- static registerTech(name, tech)
- static removeHook(type, fn) → {boolean}
- static resetFormatTime()
- static setFormatTime(customImplementation)
- static trigger(elem, event, hashopt) → {boolean|undefined}
- static use(type, middleware)
- static xhr(options) → {XMLHttpRequest|XDomainRequest}
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
AudioTrack
[module:videojs~videojs.AudioTrack]($7c53ae90d6590411.md)
EventTarget
[module:videojs~videojs.EventTarget]($a81ab49063bf6234.md)
TextTrack
[module:videojs~videojs.TextTrack]($a67d8ffe9ae75a74.md)
VideoTrack
[module:videojs~videojs.VideoTrack]($a6c6a54a707ee206.md)
Members
static browser :Object
[video.js](https://docs.videojs.com/video.js.html)
, [line 432](https://docs.videojs.com/video.js.html#line432)
A reference to the browser utility module as an object.
See:
static dom :Object
[video.js](https://docs.videojs.com/video.js.html)
, [line 560](https://docs.videojs.com/video.js.html#line560)
A reference to the DOM utility module as an object.
See:
static log :function
[video.js](https://docs.videojs.com/video.js.html)
, [line 499](https://docs.videojs.com/video.js.html#line499)
A reference to the log utility module as an object.
See:
static options :Object
[video.js](https://docs.videojs.com/video.js.html)
, [line 308](https://docs.videojs.com/video.js.html#line308)
The global options object. These are the settings that take effect if no overrides are specified when the player is created.
static players :Object
[player.js](https://docs.videojs.com/player.js.html)
, [line 4999](https://docs.videojs.com/player.js.html#line4999)
Global enumeration of players.
The keys are the player IDs and the values are either the Player instance or null
for disposed players.
static TOUCH_ENABLED :boolean
[video.js](https://docs.videojs.com/video.js.html)
, [line 441](https://docs.videojs.com/video.js.html#line441)
Use browser.TOUCH_ENABLED instead; only included for backward-compatibility with 4.x.
Deprecated:
- Since version 5.0, use browser.TOUCH_ENABLED instead.
static url :Object
[video.js](https://docs.videojs.com/video.js.html)
, [line 568](https://docs.videojs.com/video.js.html#line568)
A reference to the URL utility module as an object.
See:
static VERSION :string
[video.js](https://docs.videojs.com/video.js.html)
, [line 300](https://docs.videojs.com/video.js.html#line300)
Current Video.js version. Follows semantic versioning.
Methods
static addLanguage(code, data) → {Object
[video.js](https://docs.videojs.com/video.js.html)
, [line 482](https://docs.videojs.com/video.js.html#line482)
Adding languages so that they’re available to all players. Example: videojs.addLanguage('es', { 'Hello': 'Hola' });
Parameters:
Name | Type | Description |
---|---|---|
code | string | The language code or dictionary property |
data | Object | The data values to be translated |
Returns:
Object -
The resulting language dictionary object
static bind(context, fn, uidopt) → {function}
[utils/fn.js](https://docs.videojs.com/utils_fn.js.html)
, [line 30](https://docs.videojs.com/utils_fn.js.html#line30)
Bind (a.k.a proxy or context). A simple method for changing the context of a function.
It also stores a unique id on the function so it can be easily removed from events.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
context | Mixed | The object to bind as scope. | |
fn | function | The function to be bound to a scope. | |
uid | number | <optional> | An optional unique ID for the function to be set |
Returns:
function -
The new function that will be bound into the context given
static computedStyle(el, prop)
[utils/computed-style.js](https://docs.videojs.com/utils_computed-style.js.html)
, [line 23](https://docs.videojs.com/utils_computed-style.js.html#line23)
A safe getComputedStyle.
This is needed because in Firefox, if the player is loaded in an iframe with display:none
, then getComputedStyle
returns null
, so, we do a null-check to make sure that the player doesn’t break in these cases.
Parameters:
Name | Type | Description |
---|---|---|
el | Element | The element you want the computed style of |
prop | string | The property name you want |
static createTimeRange(start, end)
[utils/time-ranges.js](https://docs.videojs.com/utils_time-ranges.js.html)
, [line 127](https://docs.videojs.com/utils_time-ranges.js.html#line127)
Create a TimeRange
object which mimics an HTML5 TimeRanges instance.
Parameters:
Name | Type | Description |
---|---|---|
start | number | Array.<Array> | The start of a single range (a number) or an array of ranges (an array of arrays of two numbers each). |
end | number | The end of a single range. Cannot be used with the array form of the |
static createTimeRanges(start, end)
[utils/time-ranges.js](https://docs.videojs.com/utils_time-ranges.js.html)
, [line 127](https://docs.videojs.com/utils_time-ranges.js.html#line127)
Create a TimeRange
object which mimics an HTML5 TimeRanges instance.
Parameters:
Name | Type | Description |
---|---|---|
start | number | Array.<Array> | The start of a single range (a number) or an array of ranges (an array of arrays of two numbers each). |
end | number | The end of a single range. Cannot be used with the array form of the |
static deregisterPlugin(name)
[plugin.js](https://docs.videojs.com/plugin.js.html)
, [line 386](https://docs.videojs.com/plugin.js.html#line386)
De-register a Video.js plugin.
Parameters:
Name | Type | Description |
---|---|---|
name | string | 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
static extend(superClass, subClassMethodsopt) → {function}
[extend.js](https://docs.videojs.com/extend.js.html)
, [line 29](https://docs.videojs.com/extend.js.html#line29)
Used to subclass an existing class by emulating ES subclassing using the extends
keyword.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
superClass | function | The class to inherit from | ||
subClassMethods | Object | <optional> | {} | Methods of the new class |
Returns:
function -
The new class with subClassMethods that inherited superClass.
Example
var MyComponent = videojs.extend(videojs.getComponent('Component'), {
myCustomMethod: function() {
// Do things in my method.
}
});
static formatTime(seconds, guide) → {string}
[utils/format-time.js](https://docs.videojs.com/utils_format-time.js.html)
, [line 90](https://docs.videojs.com/utils_format-time.js.html#line90)
Delegates to either the default time formatting function or a custom function supplied via setFormatTime
.
Formats seconds as a time string (H:MM:SS or M:SS). Supplying a guide (in seconds) will force a number of leading zeros to cover the length of the guide.
Parameters:
Name | Type | Description |
---|---|---|
seconds | number | Number of seconds to be turned into a string |
guide | number | Number (in seconds) to model the string after |
Returns:
string -
Time formatted as H:MM:SS or M:SS
Example
formatTime(125, 600) === "02:05"
static getAllPlayers() → {Array}
[video.js](https://docs.videojs.com/video.js.html)
, [line 369](https://docs.videojs.com/video.js.html#line369)
Returns an array of all current players.
Returns:
Array -
An array of all players. The array will be in the order that Object.keys
provides, which could potentially vary between JavaScript engines.
static getComponent(name) → {Component}
[component.js](https://docs.videojs.com/component.js.html)
, [line 1719](https://docs.videojs.com/component.js.html#line1719)
Get a Component
based on the name it was registered with.
Parameters:
Name | Type | Description |
---|---|---|
name | string | The Name of the component to get. |
Returns:
The Component
that got registered under the given name.
Deprecated:
- In `videojs` 6 this will not return `Component`s that were not registered using Component.registerComponent. Currently we check the global `videojs` object for a `Component` name and return that if it exists.
static getPlayer(id) → {Player|undefined}
[video.js](https://docs.videojs.com/video.js.html)
, [line 332](https://docs.videojs.com/video.js.html#line332)
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:
Name | Type | Description |
---|---|---|
id | string | Element | An HTML element - |
Returns:
Player | undefined -
A player instance or undefined
if there is no player instance matching the argument.
static getPlayers() → {Object}
[video.js](https://docs.videojs.com/video.js.html)
, [line 316](https://docs.videojs.com/video.js.html#line316)
Get an object with the currently created players, keyed by player ID
Returns:
Object -
The created players
static getPlugin(name) → {function|undefined}
[plugin.js](https://docs.videojs.com/plugin.js.html)
, [line 438](https://docs.videojs.com/plugin.js.html#line438)
Gets a plugin by name if it exists.
Parameters:
Name | Type | Description |
---|---|---|
name | string | The name of a plugin. |
Returns:
function | undefined -
The plugin (or undefined
).
static getPlugins(namesopt) → {Object|undefined}
[plugin.js](https://docs.videojs.com/plugin.js.html)
, [line 407](https://docs.videojs.com/plugin.js.html#line407)
Gets an object containing multiple Video.js plugins.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
names | Array | <optional> | If provided, should be an array of plugin names. Defaults to all plugin names. |
Returns:
Object | undefined -
An object containing plugin(s) associated with their name(s) or undefined
if no matching plugins exist).
static getPluginVersion(name) → {string}
[plugin.js](https://docs.videojs.com/plugin.js.html)
, [line 431](https://docs.videojs.com/plugin.js.html#line431)
Gets a plugin’s version, if available
Parameters:
Name | Type | Description |
---|---|---|
name | string | The name of a plugin. |
Returns:
string -
The plugin’s version or an empty string.
static getTech(name) → {Tech|undefined}
[tech/tech.js](https://docs.videojs.com/tech_tech.js.html)
, [line 1011](https://docs.videojs.com/tech_tech.js.html#line1011)
Get a Tech
from the shared list by name.
Parameters:
Name | Type | Description |
---|---|---|
name | string |
|
Returns:
Tech | undefined -
The Tech
or undefined if there was no tech with the name requested.
static hook(type, The)
[video.js](https://docs.videojs.com/video.js.html)
, [line 217](https://docs.videojs.com/video.js.html#line217)
Add a function hook to a specific videojs lifecycle.
Parameters:
Name | Type | Description |
---|---|---|
type | string | the lifecycle to hook the function to. |
The | function | Array.<function()> | function or array of functions to attach. |
static hookOnce(type, The)
[video.js](https://docs.videojs.com/video.js.html)
, [line 230](https://docs.videojs.com/video.js.html#line230)
Add a function hook that will only run once to a specific videojs lifecycle.
Parameters:
Name | Type | Description |
---|---|---|
type | string | the lifecycle to hook the function to. |
The | function | Array.<function()> | function or array of functions to attach. |
static hooks(type, fnopt) → {Array}
[video.js](https://docs.videojs.com/video.js.html)
, [line 200](https://docs.videojs.com/video.js.html#line200)
Get a list of hooks for a specific lifecycle
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type | string | the lifecyle to get hooks from | |
fn | function | Array.<function()> | <optional> | Optionally add a hook (or hooks) to the lifecycle that your are getting. |
Returns:
Array -
an array of hooks, or an empty array if there are none.
static isCrossOrigin(url, winLocopt) → {boolean}
[utils/url.js](https://docs.videojs.com/utils_url.js.html)
, [line 165](https://docs.videojs.com/utils_url.js.html#line165)
Returns whether the url passed is a cross domain request or not.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
url | string | The url to check. | |||||||||||||
winLoc | Object | <optional> | the domain to check the url against, defaults to window.location Properties
|
Returns:
boolean -
Whether it is a cross domain request or not.
static mergeOptions(…sources) → {Object}
[utils/merge-options.js](https://docs.videojs.com/utils_merge-options.js.html)
, [line 24](https://docs.videojs.com/utils_merge-options.js.html#line24)
Merge two objects recursively.
Performs a deep merge like lodash.merge, but only merges plain objects (not arrays, elements, or anything else).
Non-plain object values will be copied directly from the right-most argument.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
sources | Array.<Object> | <repeatable> | One or more objects to merge into a new object. |
Returns:
Object -
A new object that is the merged result of all sources.
static off(elem, typeopt, fnopt)
[utils/events.js](https://docs.videojs.com/utils_events.js.html)
, [line 346](https://docs.videojs.com/utils_events.js.html#line346)
Removes event listeners from an element
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
elem | Element | Object | Object to remove listeners from. | |
type | string | Array.<string> | <optional> | Type of listener to remove. Don’t include to remove all events from element. |
fn | EventTarget~EventListener | <optional> | Specific listener to remove. Don’t include to remove listeners for an event type. |
static on(elem, type, fn)
[utils/events.js](https://docs.videojs.com/utils_events.js.html)
, [line 260](https://docs.videojs.com/utils_events.js.html#line260)
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:
Name | Type | Description |
---|---|---|
elem | Element | Object | Element or object to bind listeners to |
type | string | Array.<string> | Type of event to bind to. |
fn | EventTarget~EventListener | Event listener. |
static one(elem, type, fn)
[utils/events.js](https://docs.videojs.com/utils_events.js.html)
, [line 485](https://docs.videojs.com/utils_events.js.html#line485)
Trigger a listener only once for an event.
Parameters:
Name | Type | Description |
---|---|---|
elem | Element | Object | Element or object to bind to. |
type | string | Array.<string> | Name/type of event |
fn | Event~EventListener | Event listener function |
static parseUrl(url) → {url:URLObject}
[utils/url.js](https://docs.videojs.com/utils_url.js.html)
, [line 43](https://docs.videojs.com/utils_url.js.html#line43)
Resolve and parse the elements of a URL.
Parameters:
Name | Type | Description |
---|---|---|
url | String | The url to parse |
Returns:
url:URLObject -
An object of url details
static plugin(name, plugin)
[video.js](https://docs.videojs.com/video.js.html)
, [line 460](https://docs.videojs.com/video.js.html#line460)
Deprecated method to register a plugin with Video.js
Parameters:
Name | Type | Description |
---|---|---|
name | string | The plugin name |
plugin | Plugin | function | The plugin sub-class or function |
Deprecated:
- videojs.plugin() is deprecated; use videojs.registerPlugin() instead
static registerComponent(name, comp) → {Component}
[video.js](https://docs.videojs.com/video.js.html)
, [line 395](https://docs.videojs.com/video.js.html#line395)
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:
Name | Type | Description |
---|---|---|
name | string | The class name of the component |
comp | Component | The component class |
Returns:
The newly registered component
static registerPlugin(name, plugin) → {function}
[plugin.js](https://docs.videojs.com/plugin.js.html)
, [line 346](https://docs.videojs.com/plugin.js.html#line346)
Register a Video.js plugin.
Parameters:
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 | function | A sub-class of |
Returns:
function -
For advanced plugins, a factory function for that plugin. For basic plugins, a wrapper function that initializes the plugin.
static registerTech(name, tech)
[tech/tech.js](https://docs.videojs.com/tech_tech.js.html)
, [line 975](https://docs.videojs.com/tech_tech.js.html#line975)
Registers a Tech
into a shared list for videojs.
Parameters:
Name | Type | Description |
---|---|---|
name | string | Name of the |
tech | Object | The |
static removeHook(type, fn) → {boolean}
[video.js](https://docs.videojs.com/video.js.html)
, [line 253](https://docs.videojs.com/video.js.html#line253)
Remove a hook from a specific videojs lifecycle.
Parameters:
Name | Type | Description |
---|---|---|
type | string | the lifecycle that the function hooked to |
fn | function | The hooked function to remove |
Returns:
boolean -
The function that was removed or undef
static resetFormatTime()
[utils/format-time.js](https://docs.videojs.com/utils_format-time.js.html)
, [line 67](https://docs.videojs.com/utils_format-time.js.html#line67)
Resets formatTime to the default implementation.
static setFormatTime(customImplementation)
[utils/format-time.js](https://docs.videojs.com/utils_format-time.js.html)
, [line 60](https://docs.videojs.com/utils_format-time.js.html#line60)
Replaces the default formatTime implementation with a custom implementation.
Parameters:
Name | Type | Description |
---|---|---|
customImplementation | function | A function which will be used in place of the default formatTime implementation. Will receive the current time in seconds and the guide (in seconds) as arguments. |
static trigger(elem, event, hashopt) → {boolean|undefined}
[utils/events.js](https://docs.videojs.com/utils_events.js.html)
, [line 420](https://docs.videojs.com/utils_events.js.html#line420)
Trigger an event for an element
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
elem | Element | Object | Element to trigger an event on | |
event | EventTarget~Event | string | A string (the type) or an event object with a type attribute | |
hash | Object | <optional> | data hash to pass along with the event |
Returns:
boolean | undefined -
Returns the opposite of defaultPrevented
if default was prevented. Otherwise, returns undefined
static use(type, middleware)
[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html)
, [line 46](https://docs.videojs.com/tech_middleware.js.html#line46)
Define a middleware that the player should use by way of a factory function that returns a middleware object.
Parameters:
Name | Type | Description |
---|---|---|
type | string | The MIME type to match or |
middleware | MiddlewareFactory | A middleware factory function that will be executed for matching types. |
static xhr(options) → {XMLHttpRequest|XDomainRequest}
[video.js](https://docs.videojs.com/video.js.html)
, [line 526](https://docs.videojs.com/video.js.html#line526)
A cross-browser XMLHttpRequest wrapper.
Parameters:
Name | Type | Description |
---|---|---|
options | Object | Settings for the request. |
Returns:
XMLHttpRequest | XDomainRequest -
The request object.