Interface MKPlayerAPI

MKPlayer API.

Defines the API's supported by MKPlayer.

Hierarchy

Properties

adaptation: MKAdaptationAPI

MKPlayer Adaption APIs.

buffer: MKBufferAPI

MKPlayer Buffer APIs.

MKPlayer DRM APIs.

lowlatency: MKLowLatencyAPI

MKPlayer Low Latency APIs.

manifest: MKManifestAPI

MKPlayer Manifest APIs.

subtitles: MKSubtitlesAPI

MKPlayer Subtitles APIs.

Methods

  • Sends custom metadata to a remote receiver app (e.g. Chromecast).

    Parameters

    • metadata: any

      the custom metadata to send to the receiver.

    Returns boolean

    true if it was successful.

  • Adds a marker to the timeline.

    Note: Does not check for duplicates/overlaps at the specified time.

    Note: This API is only available when ui is enabled.

    Note: It is also recommended to call this API after playback starts as the positioning of the timeline marker depends on knowing the current seekable range. The best place to call this the first time is as soon as the first time changed event is received from TimeChanged.

    Example to place timeline marker during ongoing playback:

    var timelineMarkers = [
    { time: 24, title: 'Salto on the edge' },
    { time: 69, title: 'Interview - Marcus Gustafsson' },
    { time: 105, title: 'Parcour rating explained' },
    { time: 188, duration: 11, title: 'And we have a winner!', cssClasses: ['seekbar-marker-interval'] },
    ];

    // Call this anytime during any ongoing playback
    // to add all available timeline markers to the UI.
    timelineMarkers.map((marker) => {
    player.addTimelineMarker(marker);
    });

    Example to place timelineMarker for an AdBreak based off AdMarker:

    // list of AdBreaks
    const adBreaks = [];

    // collect AdMarkers and build the list of adBreaks
    player.on(MKPlayerEvent.AdMarker, (event) => {
    adBreaks.push(event.adMarker);

    // timeline markers cannot be added from here during ongoing plyback
    // because this callback is always reported when metadata is parsed
    // which means the time for this ad is in the future and outside the
    // current seekable range. So for upcoming adBreaks new markers can
    // only be added when the time falls within the current seekable range
    // or when the next MKPlayerEvent.AdBreakStarted event is triggered.
    });

    // global variable
    let firstTimeChangedEvent = false;

    // Wait for the playback to start and the
    // first time changed event is received to add timeline markers
    player.on(MKPlayerEvent.TimeChanged, (event) => {
    if (!firstTimeChangedEvent) {
    firstTimeChangedEvent = true;

    // add timeline markers
    adBreakList.map((marker, index) => {
    player.addTimelineMarker({time: marker.start});
    });
    }
    });

    Parameters

    Returns void

  • Initiates casting the current video to a Cast-compatible device.

    The user has to choose the target device.

    Returns void

  • Unloads the player and removes all inserted HTML elements and event handlers.

    Returns Promise<void>

    Promise resolves when the player has cleaned up all its event handlers & resources.

  • Returns the current aspect ratio of the player, or 0 if there is no style module.

    Note: the default player aspect ratio is 16:9.

    Returns number

    A number indicating the player aspect ratio (e.g. 1.6 for 16:10) or 0 in case of error.

  • Returns the current playback time in seconds of the video.

    Parameters

    Returns number

  • Returns the total duration in seconds of the current video.

    Returns number

  • Returns the current latency in seconds for the live stream.

    Returns number

    the current latency in seconds.

  • Returns the limit in seconds for time shift.

    Is either negative or 0 and applicable to live streams only.

    Returns number

  • Returns the current playback speed of the player.

    1 is the default playback speed, values between 0 and 1 refer to slow motion and values greater than 1 refer to fast forward.

    Values less or equal zero are ignored.

    Returns number

  • Returns a thumbnail image for a certain time or null if there is no thumbnail available.

    Requires a configured thumbnails track in thumbnailTrack if sideloaded thumbnails are configured.

    Requires enableHlsImageMediaPlaylistSupport to be true if thumbnail images from the HLS manifest are needed.

    When thumbnailTrack are configured, this will have preference over the thumbnails found in the HLS manifest.

    Parameters

    • time: number

      the media time for which the thumbnail should be returned.

    Returns null | MKThumbnail

    A thumbnail if a thumbnails track is configured and a thumbnail exists for the specified time, else null.

  • Returns the current time shift offset to the live edge in seconds.

    Is either negative or 0 and applicable to live streams only.

    Offset 0 indicates the current live edge.

    Returns number

  • Returns the html element that the player is embedded in, which has been provided in the player constructor.

    Returns HTMLElement

  • Returns the used HTML5 video element.

    Returns undefined | HTMLVideoElement

  • Returns the player’s volume between 0 (silent) and 100 (max volume).

    Returns number

  • Returns true if casting to another device (such as a ChromeCast) is available, otherwise false.

    Please note that this function only returns true after the CastAvailable event has fired.

    Returns boolean

  • Returns true if the video is currently casted to a device and not played in the browser, or false if the video is played locally.

    Returns boolean

  • Return true if the displayed video is a live stream.

    Returns boolean

  • Returns true if the player has been muted.

    Returns boolean

  • Returns true if the player has started playback but is currently paused.

    Returns boolean

  • Returns true if the player is currently playing, i.e. has started and is not paused.

    Returns boolean

  • Returns true if the player is currently stalling due to an empty buffer.

    Returns boolean

  • Tests if a particular ViewMode is available for selection with setViewMode.

    Parameters

    Returns boolean

    true if the tested view mode is available, else false.

  • Sets a new video source and returns a promise which resolves when the source has loaded successfully.

    Parameters

    • sourceConfig: MKSourceConfig

      the source configuration object.

    • Optional disableSeeking: boolean

      If set, seeking will be disabled.

    Returns Promise<void>

    Promise which resolves when the source is loaded and rejects when load fails.

  • Mutes the player if an audio track is available. Has no effect if the player is already muted.

    Parameters

    • Optional issuer: string

      The issuer of the API call that will be passed to events triggered by this call.

    Returns void

  • Removes all event handlers registered for the given event type.

    Parameters

    • eventType: MKPlayerEvent

      The event for which all event handlers are to be removed.

    Returns void

  • Subscribes an event handler to a player event.

    Type Parameters

    Parameters

    Returns void

  • Pauses the video if it is playing. Has no effect if the player is already paused.

    Parameters

    • Optional issuer: string

      The issuer of the API call that will be passed to events triggered by this call.

    Returns void

  • Starts playback or resumes after being paused.

    No need to call it if the player is stup with autoplay.

    Calling play has no effect when player is already playing.

    Parameters

    • Optional issuer: string

      the issuer of the API call that will be passed to events triggered by this call.

    Returns Promise<void>

    a promise which resolves as soon as playback starts. The promise can reject if the play is blocked by the browser.

  • Starts preloading the content of the currently loaded source.

    Returns void

  • Reload the currently playing source.

    Note:

    • Specifying start parameter is only supported for Live or Event asset types.
    • Specifying sourceOptions for VOD, startOffset must be positive value bewtween 0 and duration of the VOD asset and no startOffsetTimelineReference must be set.
    • Specifying sourceOptions for Live, startOffset for bookmark offset must always be an UNIX Epoch absolute timestamp and no startOffsetTimelineReference must be set.

    For more details, please refer to notes for startOffset.

    Examples

    To reload the same source

    reload()
    

    To reload same source and start at bookmark offset

    reload(undefined, {startOffset: 120});
    

    To reload same source and start 5 minutes behind live edge for live

    reload(undefined, {startOffset: -300, startOffsetTimelineReference: "end"});
    

    To reload the same source and start at a specified bookmark offset (absolute timestamp) for live

    reload(undefined, {startOffset: 1692268911.789})
    

    To reload with a new start time for live and start at the live edge

    reload("2023-06-28T10:00:00Z");

    // OR
    reload("2023-06-28T10:00:00Z", {"startOffset": 0, "startOffsetTimelineReference": "end"});

    To reload with a new start time for live and start at the beginning

    reload("2023-06-28T10:00:00Z", {"startOffset": 0, "startOffsetTimelineReference": "start"});
    

    To reload with a new start time for live and start at the specified startOffset

    const currentTime = player.getCurrentTime(); // current time used for example
    reload("2023-06-28T10:00:00Z", {"startOffset": currentTime});

    Parameters

    • Optional start: string

      ISO Date string in the format 2023-06-27T10:00:00Z

    • Optional sourceOptions: MKSourceOptions

      source options specifying start offset and timeline reference.

    Returns Promise<void>

  • Removes a marker from the timeline (by reference) and returns true if the marker has been part of the timeline and successfully removed, or false if the marker could not be found and thus not removed.

    Note: This API is only available when ui is enabled.

    Parameters

    Returns boolean

  • Seeks to the given playback time specified by the parameter time in seconds.

    The time offset specified must always be a positive value and within the current getSeekableRange.

    For Live and Events the specified time either be relative or absolute offset.

    • Calling seek(0) will take you to the start of the live window
    • Calling seek(getSeekableRange().end) will take you near the current live edge. You can also call () to jump to current live edge easily.

    Parameters

    • time: number

      The time to seek to in seconds.

    • Optional issuer: string

      The issuer of the API call that will be passed to events triggered by this call.

    Returns boolean

    true when successful.

  • Seeks to the current live edge.

    Applicable only for live sources.

    Parameters

    • Optional issuer: string

      The issuer of the API call that will be passed to events triggered by this call.

    Returns void

  • Modifies the current aspect ratio of the player.

    Parameters

    • aspectratio: string | number

      The desired aspect ratio for the player. It can be a string (e.g. '16:9' or '16/9'), or a number (e.g 1.6 for 16:10).

    Returns void

  • Sets the audio track to the ID specified by trackID.

    Available tracks can be retrieved with getAvailableAudio.

    Parameters

    • trackID: string

      The ID of the audio track to activate.

    Returns void

  • Manually sets the audio stream to a fixed quality, identified by ID.

    Has to be an ID defined in the MPD or the keyword 'auto'.

    Auto resets to dynamic switching.

    A list with valid IDs can be retrieved by calling getAvailableAudioQualities.

    Parameters

    • audioQualityID: string

      The ID of the desired audio quality or 'auto' for dynamic switching.

    Returns void

  • Set HTTP headers.

    Use this to pass your HTTP headers for all player/playback manifest requests.

    Note: It is recommended to call this method before calling load.

    Parameters

    • headers: null | MKHeaders

      HTTP headers to be used with requests and when null is passed the set headers will be cleared.

    Returns void

  • Set inhome status.

    Note: this is applicable only for registered source streams.

    This setting will only be applied when the next playback session starts. So it is expected to call this before calling load.

    Parameters

    • inhomeStatus: boolean

      the new inhome status value.

    Returns void

  • Set/Remove location detail information.

    Note: this is applicable only for registered source streams.

    This setting will only be applied when the next playback session starts. So it is expected to call this before calling load.

    Also if needed to remove the old location detail, pass null or empty string.

    Parameters

    • locationDetail: null | string

      the new location details as base64 encoded string or null / '' to remove old one.

    Returns void

  • Sets the level of player log outputs.

    Parameters

    • level: MKLogLevel

      Log level, allowed values are "debug", "log", "warn", "error" and "off"

    Returns void

  • Sets the playback speed of the player.

    Available only for HTML5 player.

    Fast forward as well as slow motion is supported.

    Slow motion is used by values between 0 and 1, fast forward by values greater than 1.

    Parameters

    • speed: number

      A playback speed factor greater than 0.

    Returns void

  • Sets a poster image. Will be displayed immediately, even if a video stream is playing.

    Parameters

    • url: string

      The URL to the poster image.

    • keepPersistent: boolean

      Flag to set the poster image persistent so it is also displayed during playback (useful for audio-only playback).

    Returns void

  • Passes an HTML video element to the player, which should be used in case of Html5 or Native playback.

    For this to take effect you must call this function before calling load.

    When no video element is set on the player, the player will create one for use internally. You may call getVideoElement to get hold of the video element in use by the player.

    Also the video element should be contained within the video container element that was passed as part of player creation.

    Example:

    ' In the HTML body
    <div id="videoContainer">
    <video id="videoElement"></video>
    </div>

    ' In the script
    let videoContainer = document.getElementById("videoContainer");
    let videoElement = document.getElementById("videoElement");
    let playerConfig = {
    key: "<license_key>",
    playback: {
    autoplay: true,
    muted: true
    }
    };

    let player = new mkplayer.MKPlayer(playerConfig, videoContainer);
    player.setVideoElement(videoElement);
    player.load(sourceConfig);

    Parameters

    • videoElement: HTMLVideoElement

      the video element to set.

    Returns void

  • Manually sets the video stream to a fixed quality, identified by ID.

    Has to be an ID defined in the Manifest/MPD or the keyword 'auto'.

    Auto resets to dynamic switching.

    A list with valid IDs can be retrieved by calling getAvailableVideoQualities.

    Parameters

    • videoQualityID: string

      ID defined in the Manifest/MPD or 'auto'.

    Returns void

  • Sets the player to a particular ViewMode.

    Will only work if the selected view mode is available and isViewModeAvailable returns true, else this call will be ignored.

    If successful, a ViewModeChanged will be fired.

    Parameters

    • viewMode: MKViewMode

      the view mode to switch the player into.

    • Optional options: MKViewModeOptions

      additional optional parameters for view modes.

    Returns void

  • Sets the player’s volume in the range of 0 (silent) to 100 (max volume). Unmutes a muted player.

    Parameters

    • volume: number

      The volume to set between 0 and 100.

    • Optional issuer: string

      The issuer of the API call that will be passed to events triggered by this call.

    Returns void

  • Unloads the current video source.

    Returns Promise<void>

  • Unmutes the player if muted.

    Parameters

    • Optional issuer: string

      The issuer of the API call that will be passed to events triggered by this call.

    Returns void

  • Update STS authToken during an ongoing playback session.

    Note: this is applicable only for registered source streams and during an ongoing playback session to update an authorization token that is about to expire (token refresh).

    Setting this before calling load will have no effect and it is expected to have the updated authorization token as part of the azuki config in the registered source config object passed to start playback of a next source.

    Parameters

    • authToken: string

      the new authorization token.

    Returns void