Class: MediaPlayer

MediaPlayer

MediaPlayer is the object used by the webapp to instanciante and control hasplayer.

new MediaPlayer()

Members


<static> dependencies

Packages declaration

<static> PUBLIC_EVENTS

ENUMS

<static> TRACKS_TYPE

Exposes the available tracks types used to manage tracks (language) switching.
Properties:
Name Type Default Description
AUDIO audio
TEXT text
See:

Methods


addEventListener(type, listener, useCapture)

Registers a listener on the specified event. The possible event types are:
  • 'error' (see error event specification)
  • 'warning' (see warning event specification)
  • 'manifestUrlUpdate' (see manifestUrlUpdate event specification)
  • 'play_bitrate' (see play_bitrate event specification)
  • 'download_bitrate' (see download_bitrate event specification)
  • 'bufferLevel_updated' (see bufferLevel_updated event specification)
  • 'state_changed' (see state_changed event specification)
  • 'cueEnter' (see cueEnter event specification)
  • 'cueExit' (see cueExit event specification)
  • Parameters:
    Name Type Description
    type string the event type for listen to, either any HTML video element event or player event.
    listener callback the callback which is called when an event of the specified type occurs
    useCapture boolean see HTML DOM addEventListener() method specification

    addPlugin(plugin)

    Adds a MediaPlayer plugin.
    Parameters:
    Name Type Description
    plugin object the plugin instance

    attachTTMLRenderingDiv(div)

    Attaches an HTML div element to be used to render rich TTML subtitles.
    Parameters:
    Name Type Description
    div HTMLDivElement An unstyled div element placed after the video element. It will be styled to match the video size and overlay z-order

    enableSubtitleExternDisplay(mode)

    Enables or disables subtitles display in a div outside video player.
    Parameters:
    Name Type Description
    mode boolean true if subtitles are displayed in a div outside video player

    enableSubtitles(value)

    Enable or disables subtitles processing.
    Parameters:
    Name Type Description
    value boolean true to enable subtitles, false to disables subtitles processing (by default subtitles are disabled)

    getAutoPlay()

    Returns the autoplay state.
    Returns:
    the autoplay state
    Type
    boolean

    getAutoSwitchQuality()

    Returns the auto switch quality state.
    Returns:
    the auto switch quality state
    Type
    boolean

    getBuildDate()

    Returns the date at which this player has been built.
    Returns:
    the date at which this player has been built
    Type
    string

    getDebug()

    Returns the debug object.
    Returns:
    the debug object
    Type
    object

    getDefaultAudioLang()

    Gets the default audio language.
    Returns:
    lang - the default audio language based on ISO 3166-2
    Type
    string

    getDefaultSubtitleLang()

    Gets the default subtitle language.
    Returns:
    lang - the default subtitle language based on ISO 3166-2
    Type
    string

    getDuration()

    Returns the media duration.
    Returns:
    the media duration in seconds, Infinity for live content
    Type
    number

    getDVRSeekOffset(value)

    TBD
    Parameters:
    Name Type Description
    value
    Returns:
    DVR seek offset

    getDVRWindowRange()

    Return the available DVR window range in case of live streams.
    Returns:
    • range - the DVR window range
      Type
      object
    • range.start - the DVR window range start time
      Type
      number
    • range.end - the DVR window range end time
      Type
      number
    • range.programStart - the DVR window range absolute program start date/time (if available, may be undefined)
      Type
      number
    • range.programEnd - the DVR window range absolute program end date/time (if available, may be undefined)
      Type
      number

    getDVRWindowSize()

    Returns the DVR window size.
    Returns:
    the DVR window size in seconds
    Type
    number

    getError()

    Returns the Error object for the most recent error.
    Returns:
    the Error object for the most recent error, or null if there has not been an error
    Type
    object

    getMetricsExt()

    Returns the metrics extension object.
    Returns:
    the metrics extension object
    Type
    object

    getMetricsFor(type)

    Returns the metrics for stream type.
    Parameters:
    Name Type Description
    type string stream type, 'video' or 'audio'
    Returns:
    the metrics array for the selected type
    Type
    Array

    getMute()

    Returns the audio mute state.
    Returns:
    true if the audio is muted, false otherwise
    Type
    boolean

    getPosition()

    Returns the current playback time/position.
    Returns:
    the current playback time/position in seconds
    Type
    number

    getQualityFor(type)

    Returns the current quality for a stream type.
    Parameters:
    Name Type Description
    type string stream type, 'video' or 'audio'
    Returns:
    the current quality level as an index of the quality (in bitrate ascending order)
    Type
    number

    getScheduleWhilePaused()

    Returns the buffering behaviour while the player is in pause.
    Returns:
    true if the player still buffers stream while in pause
    Type
    boolean

    getSelectedTrack(type)

    Returns the selected track for the stream type.
    Parameters:
    Name Type Description
    type String the stream type according to MediaPlayer.TRACKS_TYPE (see @link MediaPlayer#TRACKS_TYPE)
    Returns:
    the selected track
    Type
    Track

    getTerminalId()

    Returns the terminal ID.
    Returns:
    the terminal ID (--)
    Type
    string

    getTracks(type)

    Returns the list of available tracks for the stream type (as specified in the stream manifest). The tracks list can be retrieved once the video 'loadeddata' event has been fired.
    Parameters:
    Name Type Description
    type String the stream type according to MediaPlayer.TRACKS_TYPE (see @link MediaPlayer#TRACKS_TYPE)
    Returns:
    the available tracks for the stream type
    Type
    Array.<Track>

    getTTMLRenderingDiv()

    Returns the HTML div element previously attached (@see attachTTMLRenderingDiv)
    Returns:
    the HTML div object previously attached
    Type
    HTMLDivElement

    getVersion()

    Returns the version of the player.
    Returns:
    the version of the player
    Type
    string

    getVersionDashJS()

    Returns the version of dash.js from which this player has been built.
    Returns:
    the dash.js version
    Type
    string

    getVersionFull()

    Returns the full version of the player (including git tag).
    Returns:
    the version of the player including git tag
    Type
    string

    getVideoBitrates()

    Returns the list of available bitrates (in bitrate ascending order).
    Returns:
    array of bitrate values
    Type
    Array.<Number>

    getVideoModel()

    Returns the video model object.
    Returns:
    the video model object
    Type
    object

    getVolume()

    Returns the audio volume level.
    Returns:
    the current audio volume level, from 0.0 (silent) to 1.0 (loudest)
    Type
    number

    getWarning()

    Returns the Warning object for the most recent warning.
    Returns:
    the Warning object for the most recent warning, or null if there has not been a warning
    Type
    object

    init(video)

    Initialize the player.
    Parameters:
    Name Type Description
    video Object the HTML5 video element used to decode and render the media data

    isLive()

    Returns true if the current stream is a live stream.
    Returns:
    true if current stream is a live stream, false otherwise
    Type
    boolean

    isSubtitlesEnabled()

    Returns the subtitles processing state.
    Returns:
    true if subtitles are enabled, false otherwise
    Type
    boolean

    load(stream)

    Load/open a video stream.
    Parameters:
    Name Type Description
    stream object video stream properties object such url, startTime, prodData ...
                {
                    url : "[manifest url]",
                    startTime : [start time in seconds (optional, only for static streams)],
                    startOver : [true if start-over DVR stream (optional)],
                    protocol : "[protocol type]", // 'HLS' to activate native support on Safari/OSx
                    protData : {
                        // one entry for each key system ('com.microsoft.playready' or 'com.widevine.alpha')
                        "[key_system_name]": {
                            laURL: "[licenser url (optional)]",
                            withCredentials: "[license_request_withCredentials_value (true or false, optional)]",
                            cdmData: "[CDM data (optional)]", // Supported by PlayReady key system (using MS-prefixed EME API) only
                            serverCertificate: "[license_server_certificate (as Base64 string, optional)]",
                            audioRobustness: "[audio_robustness_level (optional)]", // Considered for Widevine key system only
                            videoRobustness: "[video_robustness_level (optional)]" // Considered for Widevine key system only
                        },
                        ...
                   }
                   ...
                }
                

    pause()

    Pauses the media playback.

    play()

    Plays/resumes playback of the media.

    removeEventListener(type, listener)

    Unregisters the listener previously registered with the addEventListener() method.
    Parameters:
    Name Type Description
    type string the event type on which the listener was registered
    listener callback the callback which was registered to the event type
    See:

    removePlugin(plugin)

    Removes a MediaPlayer plugin.
    Parameters:
    Name Type Description
    plugin object | string the plugin instance (or name) to remove

    reset(reason)

    Stops and resets the player.
    Parameters:
    Name Type Description
    reason number the reason for stopping the player. Possible values are:
  • 0 : stop during streaming at user request
  • 1 : stop when all streams are completed
  • 2 : stop after an error

  • seek(time)

    Seeks the media to the new time. For LIVE streams, this function can be used to perform seeks within the DVR window if available.
    Parameters:
    Name Type Description
    time number the new time value in seconds

    selectTrack(type, track)

    Selects the track to be playbacked for the stream type.
    Parameters:
    Name Type Description
    type String the stream type according to MediaPlayer.TRACKS_TYPE (see @link MediaPlayer#TRACKS_TYPE)
    track Track the track to select, as returned by the getTracks method
    See:

    setAutoPlay(value)

    Sets the autoplay state.
    Parameters:
    Name Type Description
    value boolean true to activate autoplay, false to disable autoplay

    setAutoSwitchQuality(value)

    Sets the auto switch quality state.
    Parameters:
    Name Type Description
    value boolean the new auto switch quality state

    setConfig(params)

    Sets player configuration parameters.
    Parameters:
    Name Type Description
    params MediaPlayer#PlayerParams parameter(s) value(s) to set.

    setDebug(value)

    Enables or disables debug information in the browser console.
    Parameters:
    Name Type Description
    value boolean true to enable debug information, false to disable

    setDefaultAudioLang(lang)

    Sets the default audio language. If the default language is available in the stream, the corresponding audio track is selected. Otherwise, the first declared audio track in the manifest is selected.
    Parameters:
    Name Type Description
    lang string the default audio language based on ISO 3166-2

    setDefaultSubtitleLang(lang)

    Sets the default subtitle language. If the default language is available in the stream, the corresponding subtitle track is selected. Otherwise, the first declared subtitle track in the manifest is selected.
    Parameters:
    Name Type Description
    lang string the default subtitle language based on ISO 3166-2

    setInitialQualityFor(type, value)

    Sets the initial quality to be downloaded for the given track type. This method has to be used before each call to load() method to set the initial quality. Otherwise, the initial quality is set according to previous bandwidth condition.
    Parameters:
    Name Type Description
    type string the track type ('video' or 'audio')
    value number the new initial quality index (starting from 0) to be downloaded
    See:

    setMute(value)

    Sets the audio mute state.
    Parameters:
    Name Type Description
    value boolean true to mute audio, false otherwise

    setQualityFor(type, value)

    Selects the quality for a stream type.
    Parameters:
    Name Type Description
    type string stream type, 'video' or 'audio'
    value number the selected quality level as an index of the quality (in bitrate ascending order)

    setScheduleWhilePaused(value)

    Sets the buffering behaviour while player is in pause.
    Parameters:
    Name Type Description
    value boolean true if the player has to buffer stream while in pause

    setTrickModeSpeed()

    Returns the current trick mode speed.
    Returns:
    the current trick mode speed
    Type
    number

    setTrickModeSpeed(speed)

    Sets the trick mode speed.
    Parameters:
    Name Type Description
    speed number the new trick mode speed (0 corresponds to normal playback, i.e. playbackRate = 1)

    setVolume(level)

    Sets the audio volume level.
    Parameters:
    Name Type Description
    level number the audio volume level, from 0.0 (silent) to 1.0 (loudest)

    stop()

    Stops the media playback and seek back to start of stream and media. Subsequently call to play() method will restart streaming and playing from beginning.

    Type Definitions


    PlayerParams

    Player parameters object. All parameters values are applied for any stream type. Parameters can be overriden specifically for audio and video track by setting parameters values in the params.audio and params.video objects.
    Type:
    • Object
    Properties:
    Name Type Description
    BufferController.minBufferTimeForPlaying number Minimum buffer level before playing, in seconds (default value = 0)
    BufferController.minBufferTime number Minimum buffer size (in seconds), if set to '-1' the maximum value between the manifest's minBufferTime and 16 sec. is considered (default value = -1)
    BufferController.bufferToKeep number The buffer size (in seconds) to keep anterior to current playing time (default value = 30)
    BufferController.liveDelay number The delay (in seconds) between the live edge and playing time, if set to '-1' the live delay is set according to minBufferTime (default value = -1)
    ABR.minBandwidth number Minimum bandwidth to be playbacked (default value = -1)
    ABR.maxBandwidth number Maximum bandwidth to be playbacked (default value = -1)
    ABR.minQuality number Minimum quality index (start from 0) to be playbacked (default value = -1)
    ABR.maxQuality number Maximum quality index (start from 0) to be playbacked (default value = -1)
    ABR.switchUpIncrementally boolean Switch up quality incrementally, or not (default value = false)
    ABR.switchUpRatioSafetyFactor number Switch up bandwith ratio safety factor (default value = 1.5)
    ABR.latencyInBandwidth boolean Include (or not) latency in bandwidth (default value = true)
    ABR.switchLowerBufferTime number Buffer level (in seconds) under which switching down to lowest quality occurs (default value = -1)
    ABR.switchLowerBufferRatio number Buffer level (as percentage of buffer size) under which switching down to lowest quality occurs (default value = 0.25)
    ABR.switchDownBufferTime number Buffer level (in seconds) under which switching down quality occur, if unsufficient bandwidth (default value = -1)
    ABR.switchDownBufferRatio number Buffer level (as percentage of buffer size) under which switching down quality occurs, if unsufficient bandwidth (default value = 0.5)
    ABR.switchUpBufferTime number Buffer level (in seconds) upper which switching up quality occurs, if sufficient bandwidth (default value = -1)
    ABR.switchUpBufferRatio number Buffer level (as percentage of buffer size) upper which switching up quality occurs, if sufficient bandwidth (default value = 0.75)
    ABR.droppedFramesMinRatio number The number of dropped frames (as a ratio to total video frames) from which switching up quality is disabled (default value = 0.1)
    ABR.droppedFramesMaxRatio number The number of dropped frames (as a ratio to total video frames) from which quality is switched down (default value = 0.3)
    ManifestLoader.RetryAttempts number Number of retry attempts for downloading manifest file when it fails (default value = 2)
    ManifestLoader.RetryInterval number Interval (in milliseconds) between each retry attempts for downloading manifest file (default value = 500)
    FragmentLoader.RetryAttempts number Number of retry attempts for downloading segment files when it fails (default value = 2)
    FragmentLoader.RetryInterval number Interval (in milliseconds) between each retry attempts for downloading segment files (default value = 500)
    Protection.licensePersistence boolean Provides or not license persistence at application level, in case no persistence is provided by the CDM (default value = false)
    backoffSeekToEnd number Backoff value (in seconds) when seeking at end/duration (default value = 2)
    video Object Video parameters (parameters for video track)
    audio Object audio parameters (parameters for audio track)

    Events


    bufferLevel_updated

    The bufferLevel_updated event is fired when the buffer level changed.
    Parameters:
    Name Type Description
    event CustomEvent the event
    Properties
    Name Type Description
    detail object the event data
    Properties
    Name Type Description
    type string the stream type ('audio' or 'video')
    level number the buffer level (in seconds)

    cueEnter

    The cueEnter event is fired when a subtitle cue needs to be displayed.
    Parameters:
    Name Type Description
    event object the event
    Properties
    Name Type Description
    type object the event type ('cueEnter')
    data object the event data
    Properties
    Name Type Description
    text object the subtitle text
    style.backgroundColor string the background color
    style.color string the font color
    style.fontFamily string the font family
    style.fontSize string the font size

    cueExit

    The cueExit event is fired when a subtitle cue needs to be erased.
    Parameters:
    Name Type Description
    event object the event
    Properties
    Name Type Description
    type object the event type ('cueExit')
    data object the event data
    Properties
    Name Type Description
    text object the subtitle text
    style.backgroundColor string the background color
    style.color string the font color
    style.fontFamily string the font family
    style.fontSize string the font size

    download_bitrate

    The download_bitrate event is fired when the current downloaded bitrate has changed.
    Parameters:
    Name Type Description
    event CustomEvent the event
    Properties
    Name Type Description
    detail object the event data
    Properties
    Name Type Description
    type string the stream type ('audio' or 'video')
    bitrate number the new bitrate
    representationId string the corresponding representation id (from manifest)
    time number the current video time
    width number in case of video stream, the video width of the representation
    height number in case of video stream, the video height of the representation

    error

    The error event is fired when an error occurs. When the error event is fired, the application shall stop the player.
    Parameters:
    Name Type Description
    event object the event
    Properties
    Name Type Description
    type object the event type ('error')
    data object the event data
    Properties
    Name Type Description
    code string error code
    message string error message
    data object error additionnal data

    manifestUrlUpdate

    The manifestUrlUpdate event is fired when the URL of the manifest may have to be refreshed, since the player failed to download the manifest file (URL expiration for example). The application shall therefore provide an updated manifest URL by using the method refreshManifest
    Parameters:
    Name Type Description
    event object the event
    Properties
    Name Type Description
    type object the event type ('manifestUrlUpdate')
    data object the event data
    Properties
    Name Type Description
    url object the current manifest url

    play_bitrate

    The 'play_bitrate' event is fired when the current played bitrate has changed.
    Parameters:
    Name Type Description
    event CustomEvent the event
    Properties
    Name Type Description
    detail object the event data
    Properties
    Name Type Description
    type string the stream type ('audio' or 'video')
    bitrate number the new bitrate
    representationId string the corresponding representation id (from manifest)
    time number the current video time
    width number in case of video stream, the video width of the representation
    height number in case of video stream, the video height of the representation

    state_changed

    The state_changed event is fired when the player state changed.
    Parameters:
    Name Type Description
    event CustomEvent the event
    Properties
    Name Type Description
    detail object the event data
    Properties
    Name Type Description
    type string the stream type ('audio' or 'video')
    state string the current state ('stopped', 'buffering', 'seeking' or 'playing')

    warning

    The warning event is fired when a warning occurs.
    Parameters:
    Name Type Description
    event object the event
    Properties
    Name Type Description
    type object the event type ('warning')
    data object the event data
    Properties
    Name Type Description
    code string warning code
    message string warning message
    data object warning additionnal data