Class: Player

Player


new Player(tag [, options] [, ready])

Player class, inherits from videojs Player class.

Parameters:
Name Type Argument Description
tag Element

The original video tag used for configuring options

options Object <optional>

Player Options

ready function <optional>

Ready callback

Extends

  • videojs.Player

Members


analytics

Getter for analytics_


entitlement


entitlementEngine

Set the entitlement engine


entitlementEngine


preloadManager

Getter for preloadManager_


version

Player version

Methods


aspectRatio( [ratio])

Get/Set the aspect ratio

Parameters:
Name Type Argument Description
ratio String <optional>

Aspect ratio for player

Returns:

aspectRatio


bitrate(value)

Get/Set bitrate

Will always return a bitrate equal to the current video bitrate. However it may change due to dynamic switching.

Setting this value disable dynamic switching, and fixes the bitrate as specified.
To set a ceiling, but allow it to dynamically switch quality when
able use setMaxBitrate instead

Parameters:
Name Type Description
value Number

Bitrate to set

Returns:

bitrate when getting

Type
Number

bitrates()

Returns a list of available bitrates

Returns:

) Array of available bitrates

Type
Array.<Number>

buffered()

Get a TimeRange object with the times of the video that have been downloaded
If you just want the percent of the video that's been downloaded,
use bufferedPercent.

    // Number of different ranges of time have been buffered. Usually 1.
    numberOfRanges = bufferedTimeRange.length,
    // Time in seconds when the first range starts. Usually 0.
    firstRangeStart = bufferedTimeRange.start(0),
    // Time in seconds when the first range ends
    firstRangeEnd = bufferedTimeRange.end(0),
    // Length in seconds of the first time range
    firstRangeLength = firstRangeEnd - firstRangeStart;
Returns:

A mock TimeRange object (following HTML spec)

Type
Object

bufferedEnd()

Get the ending time of the last buffered time range
This is used in the progress bar to encapsulate all time ranges.

Returns:

The end of the last buffered time range

Type
Number

bufferedPercent()

Get the percent (as a decimal) of the video that's been downloaded

    var howMuchIsDownloaded = myPlayer.bufferedPercent();

0 means none, 1 means all.
(This method isn't in the HTML5 spec, but it's very convenient)

Returns:

A decimal between 0 and 1 representing the percent

Type
Number

canPlayType(type)

Check whether the player can play a given mimetype

Parameters:
Name Type Description
type String

The mimetype to check

Returns:

'probably', 'maybe', or '' (empty string)

Type
String

canRestart()

Returns:

true if allowed to restart the playback of the current asset

Type
Boolean

canSeekTo()

Check restriction if we can seek


createEl()

Create the component's DOM element

Returns:
Type
Element

currentTime(seconds)

Get or set the current time (in seconds)

    // get
    var whereYouAt = myPlayer.currentTime();
    // set
    myPlayer.currentTime(120); // 2 minutes into the video
Parameters:
Name Type Description
seconds Number | String

The time to seek to

Returns:
  • The time in seconds, when not setting

    Type
    Number
  • self, when the current time is set

    Type
    Player

dimension(dimension [, value])

Get/set dimension for player

Parameters:
Name Type Argument Description
dimension String

Either width or height

value Number <optional>

Value for dimension

Returns:
Type
Component

disableTimeShift(disabled)

Disables timeshifting for livestreams

Setting this to true, hides the player progress controlbar

Parameters:
Name Type Description
disabled Boolean

dispose()

Destroys the video player and does any necessary cleanup

    myPlayer.dispose();

This is especially helpful if you are dynamically adding and removing videos
to/from the DOM.


duration(seconds)

Get the length in time of the video in seconds

    var lengthOfVideo = myPlayer.duration();

NOTE: The video must have started loading before the duration can be
known, and in the case of Flash, may not be known until the video starts
playing.

Parameters:
Name Type Description
seconds Number

Duration when setting

Returns:

The duration of the video in seconds when getting

Type
Number

enterFullWindow()

When fullscreen isn't supported we can stretch the video container to as wide as the browser will let us.


exitFullscreen()

Return the video to its normal size after having been in full screen mode

    myPlayer.exitFullscreen();
Returns:

self

Type
Player

exitFullWindow()

Exit full window


fluid(bool)

Add/remove the vjs-fluid class

Parameters:
Name Type Description
bool Boolean

Value of true adds the class, value of false removes the class


fullWindowOnEscKey(event)

Check for call to either exit full window or full screen on ESC key

Parameters:
Name Type Description
event String

Event to check for key press


getBitrate()

Get current bitrate

Always returns the current bitrate, unlike bitrate() which returns 0 if ABR is enabled

Returns:

bitrate when getting

Type
Number

getCache()

Get object for cached values.

Returns:
Type
Object

getMaxBitrate()

Returns:

bitrate in kbps

Type
Number

getProgram()

Get the currently playing program


getRestrictions()

Get restrictions


height( [value])

Get/set player height

Parameters:
Name Type Argument Description
value Number <optional>

Value for height

Returns:

Height when getting

Type
Number

isFullscreen( [isFS])

Check if the player is in fullscreen mode

    // get
    var fullscreenOrNot = myPlayer.isFullscreen();
    // set
    myPlayer.isFullscreen(true); // tell the player it's in fullscreen

NOTE: As of the latest HTML5 spec, isFullscreen is no longer an official
property and instead document.fullscreenElement is used. But isFullscreen is
still a valuable property for internal player workings.

Parameters:
Name Type Argument Description
isFS Boolean <optional>

Update the player's fullscreen state

Returns:
  • true if fullscreen false if not when getting

    Type
    Boolean
  • self when setting

    Type
    Player

isLive()

Returns if the player is playing a livestream

Returns:
Type
Boolean

loadAsset(assetId [, programId] [, callback])

Load an asset for playback

Uses the entitlementEngine to load a entitlement

Parameters:
Name Type Argument Default Description
assetId String

Identifier of the asset or channel to load

programId String <optional>
null

(optional) Identifier of the program to load

callback function <optional>

Callback when entitlement request has completed


loadAssetInternal_()

Load an asset for playback


loadAssets(playlist [, callback])

Load an list of assets for playback

Uses the entitlementEngine to load a entitlement

Parameters:
Name Type Argument Description
playlist Array

An list of assets to load, {assetId and/or programId} or src (mpd) or entitlement

callback function <optional>

Callback when entitlement request has completed


loadEntitlementEngine(name)

Loads a new entitlement engine on the Player

The entitlement engine must be registered using EntitlementEngine#registerEntitlementEngine

Parameters:
Name Type Description
name String

Name of the entitlement engine


muted( [muted])

Get the current muted state, or turn mute on or off

    // get
    var isVolumeMuted = myPlayer.muted();
    // set
    myPlayer.muted(true); // mute the volume
Parameters:
Name Type Argument Description
muted Boolean <optional>

True to mute, false to unmute

Returns:
  • True if mute is on, false if not when getting

    Type
    Boolean
  • self when setting mute

    Type
    Player

options()

Set options on player and tech

Returns:

options

Type
Object

pause()

Pause the video playback

    myPlayer.pause();
Returns:

self

Type
Player

paused()

Check if the player is paused

    var isPaused = myPlayer.paused();
    var isPlaying = !myPlayer.paused();
Returns:

false if the media is currently playing, or true otherwise

Type
Boolean

play()

start media playback

    myPlayer.play();
Returns:

self

Type
Player

playEntitlement(entitlement)

Plays an entitlement

Automatically select a playback tech based on the entitlement and prepares playback.

Parameters:
Name Type Description
entitlement Object

Entitlement returned from entitlementengine


playNextPlaylistItem_()

Loads next asset in the playlist


remainingTime()

Calculates how much time is left.

    var timeLeft = myPlayer.remainingTime();

Not a native video element function, but useful

Returns:

The time remaining in seconds

Type
Number

requestFullscreen()

Increase the size of the video to full screen

    myPlayer.requestFullscreen();

In some browsers, full screen is not supported natively, so it enters
"full window mode", where the video fills the browser window.
In browsers and devices that support native full screen, sometimes the
browser's default controls will be shown, and not the Video.js custom skin.
This includes most mobile devices (iOS, Android) and older versions of
Safari.

Returns:

self

Type
Player

restart()

Reset and restart current playback

This is done by re-fetching the entitlement.


scrubbing(isScrubbing)

Returns whether or not the user is "scrubbing". Scrubbing is when the user
has clicked the progress bar handle and is dragging it along the progress bar.

Parameters:
Name Type Description
isScrubbing Boolean

True/false the user is scrubbing

Returns:
  • The scrubbing status when getting

    Type
    Boolean
  • The player when setting

    Type
    Object

segments()

Get segments from tech


selectSource(sources)

Select source based on tech-order or source-order
Uses source-order selection if options.sourceOrder is truthy. Otherwise,
defaults to tech-order selection

Parameters:
Name Type Description
sources Array

The sources for a media asset

Returns:

Object of source and tech order, otherwise false

Type
Object | Boolean

setAnalytics(analytics [, disposeOld])

Sets the external analytics engine (should be set before asset load)

Parameters:
Name Type Argument Default Description
analytics Object

external analytics engine

disposeOld Boolean <optional>
true

(optional) if true, disposes old analytics engine


setMaxBitrate(bitrate)

Set max bit rate

Setting this to NaN will clear the max bitrate

Parameters:
Name Type Description
bitrate Number

in kbps


src(source)

The source function updates the video source

To play an entitlement use the playEntitlement method instead

There are three types of variables you can pass as the argument.
URL String: A URL to the the video file. Use this method if you are sure
the current playback technology (HTML5/Flash) can support the source you
provide. Currently only MP4 files can be used in both HTML5 and Flash.

    myPlayer.src("http://www.example.com/path/to/video.mp4");

*Source Object (or element): * A javascript object containing information
about the source file. Use this method if you want the player to determine if
it can support the file using the type information.

    myPlayer.src({ type: "video/mp4", src: "http://www.example.com/path/to/video.mp4" });

*Array of Source Objects: * To provide multiple versions of the source so
that it can be played using HTML5 across browsers you can use an array of
source objects. Video.js will detect which version is supported and load that
file.

    myPlayer.src([
      { type: "video/mp4", src: "http://www.example.com/path/to/video.mp4" },
      { type: "video/webm", src: "http://www.example.com/path/to/video.webm" },
      { type: "video/ogg", src: "http://www.example.com/path/to/video.ogv" }
    ]);
Parameters:
Name Type Description
source String | Object | Array | Entitlement

The source URL, object or array of sources

Returns:
  • The current video source when getting

    Type
    String
  • The player when setting

    Type
    String

supportsFullScreen()

Check to see if fullscreen is supported

Returns:
Type
Boolean

timeShiftEnabled()

Get timeShiftEnabled

Returns:

if timeShift is enabled

Type
Boolean

volume(percentAsDecimal)

Get or set the current volume of the media

    // get
    var howLoudIsIt = myPlayer.volume();
    // set
    myPlayer.volume(0.5); // Set volume to half

0 is off (muted), 1.0 is all the way up, 0.5 is half way.

Parameters:
Name Type Description
percentAsDecimal Number

The new volume as a decimal percent

Returns:
  • The current volume when getting

    Type
    Number
  • self when setting

    Type
    Player

width( [value])

Get/set player width

Parameters:
Name Type Argument Description
value Number <optional>

Value for width

Returns:

Width when getting

Type
Number