Constructor will be exported in CommonJS.
var Player = require('rx-player')
It is possible to give a <video>
element when you instanciate it. Otherwise, it will be created.
Returns playback state of the player. Available states are :
STOPPED
: there is no information about the current stream (beginning state or afterstop()
is called)LOADING
: the stream and encryption information, if needed, are loadingLOADED
: the player is ready to playENDED
: the player has reached the end of thre stream orendTime
with successPLAYING
: the content is currently playingPAUSED
: playback has been paused by the userBUFFERING
: the player has reached the end of the buffer and is waiting for data to be appended.SEEKING
: the player has reached the end of the buffer because of an action of seeking by the user
State chart:
-------------
| STOPPED | <-----------------+
------------- | stop() or "error" event
| |
-------| loadVideo() -------------------------------------------------------
| v ----------------------- |
| ----------- ------------ play() ----------- | ----------- |
| | LOADING | --> | LOADED | ---|---> | PLAYING | ----|--> | ENDED | |
| ----------- ------------ autoPlay ----------- | ----------- |
| | | ^ | |
| --------------- | play() | | pause() | |
| | BUFFERING | -----> | v | | |
| | or | | ----------- | |
| | SEEKING | <----- | | PAUSED | | |
| --------------- | ----------- | |
| ----------------------- |
----------------------------------------------------------------------------
Returns true
if the content is a live content.
Returns the url of content's manifest.
Returns the total duration of the content. Infinity
for a live stream.
Returns in seconds the duration of the loaded video on the current range.
Returns in seconds the duration of the played video on the current range.
Returns the
Returns the text-track element used by the player to inject subtitles.
Returns the current playback position :
- in seconds for an on-demand content
- with a
Date
object for live content.
Returns the start playback position :
- in seconds for an on-demand content
- with a
Date
object for live content.
Returns the end playback position.
- in seconds for an on-demand content
- with a
Date
object for live content.
Returns the current playback speed.
Returns the value of current volume, as a float between 0 and 1.
Returns true
if player is in fullscreen mode.
Returns an array availables languages/subtitles.
Returns current language/subtitle. null
if not set.
Returns an array of availabes video/audio bitrates, in bits per seconds.
Returns current video/audio bitrate, in bits per seconds.
Returns the video/audio bitrate maximum. 0 if no limit.
Returns the size of the video/audio buffer.
This is a list of methods you can use to change player stats.
Load a video stream given the url of its manifest. This method can be call anytime, even if a stream is already loaded an played by the player. In this case, the player states will be cleared, and the new stream will be loaded.
-
options.url, options.keySystems
To load an encrypted stream, at least one
KeySystem
object must be given. ThisKeySystem
provides interface to specify the license retrieval strategy.{ url, keySystems: [keySystem...], subtitles }
: an object containing the URL of an encrypted stream, with a list ofKeySystem
to decrypt it
Subtitles
is array of object with the following interface:interface Subtitles { string url, string mimeType string [language], Array<string> [languages], },
The player is responsible to use the right
KeySystem
which is compatible to user platform.KeySystem
is an object with the following interface:interface KeySystem { // String providing the supported DRM(s). // Currently, available DRM(s) are playready (Microsoft), widevine (Google), or clearkey string type; // Method called with the DRM challenge as a parameter // It returns a Promise corresponding to XHR made to the server with the // challenge as an ArrayBuffer Promise<ArrayBuffer> getLicense((ArrayBuffer) challenge); // Optional Boolean specifying if the keySystem needs to be persisted. // If true you need to pass a LicenseStorage with interface below. boolean persistentLicense; LicenseStorage licenseStorage; // Booleans to parametrize the use of persistentState or // distinctiveIdentifier functionnalities. See eme spec for // more details. Both are false by default. boolean persistentStateRequired; boolean distinctiveIdentifierRequired; }
interface LicenseStorage { Array save(); void load(Array entries); }
For more informations about EME, take a look to the W3C specification.
-
options.timeFragment
Parameter allowing to specify the start and the end of the video. This parameter can be provided with following formats :
- a string followuing the MediaFragment standard (naming time only):
"12,120"
,",10"
,"10"
etc. - an object with javascript timestamps
{ [start]: Number, [end]: Number }
- an object with
Date
objects{ [start]: Date, [end]: Date }
- a string followuing the MediaFragment standard (naming time only):
-
options.transport
Parameter allowing to specify the type of "transport" used by the player to load manifest and media chunks. It is possible to choose between the available transports given a string. Currently, the available transports are :
dash
: DASH transport implementationsmooth
: SmoothStreaming transport implementationdirectfile
: Use
It is also possible to write your own transport, by giving a function returning an object containing those parameters
{ manifestPipeline, segmentPipeline, textTrackPipeline }
, where each parameter is aPipeline
object with the following interface:interface Pipeline { Observable resolver(infos), Observable loader(infos), Observable parser(infos), }
-
options.transportOptions
Object which is used as a parameter of the transport method each time the player is instanciated.
-
options.initVideoBitrate
/options.initAudioBitrate
Number used as initial video and audio bitrates by the adaptive streaming.
Starts video playback. Should be called when the stream is ready, eg. when state machine reaches the state LOADED
.
Pauses the video playback.
Stops video playback and clean the player, to put back the machine state into start state.
Changes the video playback speed.
Changes the video position given a parameter :
- in seconds for an on-demand content
- with a
Date
object for live content.
In case of a live video stream, take back position to live position. This is an alias to seekTo(Date.now())
.
Changes position to start position. This is an alias to seekTo(start content timestamp)
.
This methods allow to toggle the fullscreen state of the browser.
Sets the video volume, given a float between 0.0 and 1.0.
Sets volume to 0.0 and record volume value, allowing then to unmute.
Sets volume to recorded value before muting it.
Changes the audio track to the one matching the audio language given in parameter. It is possible to list the available languages using the method getAvailableLanguages()
.
Changes the subtitle track to the one matching the subtitle language given in parameter. It is possible to list the available subtitles using the method getAvailableSubtitles()
. If null
is given, subtitle are disabled.
Sets a specific bitrate for the audio/video stream. The given bitrate must match one bitrate of the list returned by getAvailableVideoBitrates/getAvailableAudioBitrates
method. This method disables the auto-adaptive mode of the player. Giving 0, auto-adaptive is on again.
Sets a maximum limit in the bitrate chosen by the auto-adaptive player strategy. If the given value is negative, the limit is disabled.
Sets the buffer size in seconds. If 0 is given, default value is used (30 seconds, in the inital implementation).
Errors have categorized is thoses types, accessible via the type
attribute:
NETWORK_ERROR
: network related error, thereason
attribute is aRequestError
MEDIA_ERROR
: media related error (decoding, parsing of any media related asset)ENCRYPTED_MEDIA_ERROR
: encryption and EME related errorsINDEX_ERROR
: playlist index access errorOTHER_ERROR
: any other type of error
A code
attribute may also be associated to the error:
PIPELINE_RESOLVE_ERROR
PIPELINE_LOAD_ERROR
PIPELINE_PARSING_ERROR
MANIFEST_PARSE_ERROR
MANIFEST_INCOMPATIBLE_CODECS_ERROR
MEDIA_IS_ENCRYPTED_ERROR
KEY_ERROR
KEY_STATUS_CHANGE_ERROR
KEY_UPDATE_ERROR
KEY_LOAD_ERROR
KEY_LOAD_TIMEOUT
INCOMPATIBLE_KEYSYSTEMS
BUFFER_APPEND_ERROR
BUFFER_FULL_ERROR
BUFFER_INDEX_ERROR
BUFFER_TYPE_UNKNOWN
MEDIA_ERR_ABORTED
MEDIA_ERR_NETWORK
MEDIA_ERR_DECODE
MEDIA_ERR_SRC_NOT_SUPPORTED
MEDIA_SOURCE_NOT_SUPPORTED
MEDIA_KEYS_NOT_SUPPORTED
OUT_OF_INDEX_ERROR
UNKNOWN_INDEX
Errors also have a fatal
attribute indicating whether or not they where fatal to the playback and an optional reason
attribute with the original error they may originate from.
Error types and codes enums can be accessed via RxPlayer.getErrorTypes()
and RxPlayer.getErrorCodes()
.
Adds a listener on an event. The avaiable events are :
"playerStateChange", string
: changes in the state machine of the player."progress", string
: changes in the buffer state"currentTimeChange", float
: changes in the currentTime"languageChange", string
: changes in audio language"subtitleChange", string
: changes in subtitle track"audioBitrateChange", int
: changes in audio bitrate"videoBitrateChange", int
: changes in video bitrate"fullscreenChange", bool
: changes in fullscreen state"error", Error
: asynchronous error that was fatal to playback"warning", Error
: asynchronous error that was not fatal to playback
Removes an event listener