Media Player API

The following sections provide the KONtx Media Player API reference documentation:

See these additional sections for more details:

KONtx.media.Captions

closed captions list

The KONtx.media.Captions class provides a list of captions entries for the KONtx.media.PlaylistEntry of the KONtx Framework media player.

The constructor sets the KONtx.cc.renderer value based on the incoming configuration property renderer. By default, hardware-based rendering is selected if avaialble on the device ("auto"), otherwise Yahoo provides software-based rendering ("yahoo").

See the section on Chapter 7, Closed Captions for more information.

Example

Properties

Property

Type

Description

entries

array

Array of KONtx.media.CaptionsEntry Objects.

isMultiLanguage

Boolean

Pseudo-property Boolean value that is set to true if the number of entries is greater than one.

name

string

String-based name of the captions list set to "MediaCaptions".

Methods

KONtx.media.Captions addEntries(Array entries);

Adds multiple captions entries to the caption list. The entries parameter is an array of KONtx.media.CaptionsEntry Objects. Returns the updated captions list.

KONtx.media.Captions addEntry(KONtx.media.CaptionsEntry entry);

Adds the single given entry to the captions list. Calls the addEntries(entry) method and returns the updated captions list.

void clearEntries();

Empties the captions entries array.

KONtx.media.CaptionsEntry getDefaultEntry();

Returns the captions entries array item at position zero.

void getEntryByIndex(int index);

Returns the captions entry at the position in the captions list specified by the given index.

void getEntryByLanguage(String lang);

Returns the captions entry identified by the specified language lang.

void parser(String url, function callback);

The given url refers to the specific TTML URL provided by each playlist entry. Take the URL representing the XML formatted TTML document and process it to normalize the structure as a JSON Object. Execute the given callback function with the JSON payload to send render data back to the captions controller. This function must be executed or the renderer will not be called.

void removeEntry(int index);

Removes the specified captions entry with the specified index.

KONtx.media.CaptionsEntry

closed captions entry

The KONtx.media.CaptionsEntry class provides a captions entry for the captions list in the KONtx.media.PlaylistEntry class of the KONtx Framework media player.

See the section on Chapter 7, Closed Captions for more information.

Example

Properties

Property

Type

Description

lang

String

The language of the closed captions. Default value is "en" for English.

parser

Function

Parser function defined by the configuration.

url

String

The closed captions TTML URL. Default value is null.

Methods

KONtx.media.CaptionsEntry addEntry(String url, String lang, Function parser);

Creates a caption entry from the given url, lang, and parser function. If the url is null no operation occurs.

void parser(String url, Function callback);

The given url refers to the specific TTML URL provided by each playlist entry. Take the URL representing the XML formatted TTML document and process it to normalize the structure as a JSON Object. Execute the given callback function with the JSON payload to send render data back to the captions controller. This function must be executed or the renderer will not be called.

KONtx.media.Playlist

media player playlist

The KONtx.media.Playlist class provides a list of media entries for the KONtx Framework media player.

Example

Properties

Property

Type

Description

autostart

Boolean

Deprecated property. The default value is false.

forcePlay

Boolean

Set this to true to force playback of the lowest bitrate stream, even if the consumer’s bandwidth is detected as being lower than the lowest bitrate stream provided. An error event is returned from the KONtx media player if forcePlay is set to false and the consumer’s bandwidth tests lower than the lowest bitrate stream provided. The default value is true.

repeatAll

Boolean

Enables looping of the playlist when the playback finishes for the last entry in the playlist. If set to true the looping occurs, if set to false, playback will stop at the last entry of the playlist. The default value is false.

Methods

KONtx.media.Playlist addEntries(Array entries);

Adds multiple playlist entries to the playlist. The entries parameter is an array of KONtx.media.PlaylistEntry Objects. Returns the updated playlist.

KONtx.media.Playlist addEntry(KONtx.media.PlaylistEntry entry);

Adds the single given entry to the playlist. Calls the addEntries(entry) method and returns the updated playlist.

KONtx.media.Playlist addEntryByURL(string url, int bitrate, int startIndex, [KONtx.media.Captions captions]);

Allows you to add an entry using the url when all you have is a single bitrate to playback for each playlist entry. If the closed captioning module is implemented, adds the given captions data. Returns the updated playlist.

void clearEntries();

Empties the playlist entries array.

void removeEntry(int index);

Removes the specified playlist entry with the index you provide.

KONtx.media.PlaylistEntry

media player playlist entry

The KONtx.media.PlaylistEntry class provides a playlist entry for the KONtx Framework media player. The playlist entry configuration allows for providing the following instantiation options:

  • A URL and bitrate. If closed captioning is implemented, a captions list can be added.
  • Just a URL.
  • An array of streams. Each element in the array is an Object with a url property and a bitrate property. If the bitrate is not provided for a stream but is provided in the main config, then all streams without a provided bitrate inherit this value.
  • A URL and an array of streams. Both will be appended together.
  • Nothing on instantiation, then calling addURL() to add an array of streams before adding the entry to the playlist.

If you provide multiple streams and do not provide multiple bitrates, then the stream that is selected will be non-deterministic. If you do provide multiple bitrates, but do not provide a connection bandwidth to the media player, then the highest bitrate stream will be selected. If you do provide a bitrate and a connection bandwidth to the media player, then the stream selected will be the fastest one supported by the consumer’s current connection speed.

Example

Properties

Property

Type

Description

url

String

The media URL. Default value is null.

bitrate

int

The bitrate of the video. Default value is null.

startIndex

int

The time index to start playback of the video. Default value is null.

streams

Array

An array of Objects with a string url property and an integer bitrate property. If the bitrate is not provided for a stream item in the array but is provided in the main configuration KONtx.media.PlaylistEntry.bitrate, then all stream items in the streams array without a bitrate inherit this value. If a stream item in the array does not have a url, the error "Invalid stream: must at minimum provide a URL" is thrown.

Methods

KONtx.media.PlaylistEntry addURL(string url, int bitrate, [KONtx.media.Captions captions]);

Creates a stream from the given url and bitrate and adds it to the streams array for this entry. If closed captioning is implemented the given captions is used for captions data. If the url is null, the error "Invalid stream: must at minimum provide a URL" is thrown. Returns the updated entry.

KONtx.media.Captions getCaptions();

If closed captioning is implemented returns the captions list.

Boolean streamsReady(Function callback);

This method is called by the KONtx media player to see if the streams are ready before fetching them. If you have streams which expire quickly and need to be refetched immediately before playback, override this method, save the callback passed in as the parameter and return false. Once your streams are ready, call the callback handler and the media player will resume. Please note, this method will be called again after you call the callback handler, so you need to return true the second time through the method or you will create an endless loop of fetching fresh URLs.

KONtx.mediaplayer

Toolbox media player

The KONtx.mediaplayer interface defines the KONtx Framework media player API.

Example

Properties

Property

Type

Description

debugInternals

Object

Normally all of the inner workings of the API are enclosed behind a public/private API separation. The debugInternals property can be used via the console to gain access to the complete “private” scope. Do not access this method in your TV App code.

isPlaylistEntryActive

Boolean

Boolean indicating if the current playlist entry is in one of the active states. These states are currently defined as PLAY, PAUSE, FASTFORWARD, REWIND, BUFFERING, or INFOLOADED. This state list is subject to change.

playlist.currentEntry

KONtx.media.Playlist

The currently selected playlist entry if one is set.

playlist.currentIndex

Object

Object with entry and stream properties. The entry property is the zero-based index of the currently selected playlist entry (if one is selected). The stream property is the zero-based index of the currently selected stream in the playlist entry (if one is selected).

tvapi.activeControl

TVControl

The active TVControl Object. Not for general use. Read-only.

tvapi.activeDRM

TVDRMInfo

The active TVDRMInfo Object. Creates an instance of a TVWidevineDRMInfo Object. Not for general use. Read-only.

tvapi.activeInput

TVNetworkInput

The active TVNetworkInput Object. Not for general use. Read-only.

tvapi.activeOutput

TVOutput

The active TVOutput Object. Not for general use. Read-only.

tvapi.activePath

TVPath

The active TVPath Object. Not for general use. Read-only.

tvapi.currentHTTPErrorCode

int

The HTTP error code as returned by the tvapi.activeInput or -1 if no error. Read-only.

tvapi.currentMediaDuration

int

The length of the currently playing content in milliseconds. Read-only.

tvapi.currentPlayerState

int

The current player state to be compared against the constants.states enumeration. Read-only.

tvapi.currentPlayerStatus

int

The current playing status, from a subset of the constants.states enumeration including PLAY, FASTFORWARD, REWIND, PAUSE, INIT, and STOP. Cannot be BUFFERING, BUFFEREMPTY, nor INFOLOADED. Read-only.

tvapi.currentQOS

Object

The current Quality of Service status Object with the following attributes: bitrates — an array<int> of possible bitrates (bytes per second) from the current DRM Object, currentBitrateIndex — an integer index for the current bitrate in the bitrates array, and bitrate — the current bitrate from the bitrates array.

tvapi.currentTimeIndex

int

The current time index of the playing content in milliseconds. Read-only.

Methods

void control.fastforward(int increment);

Tells the media player to fast forward the current content at the specified increment if supported by the media player. Supported increments are 2, 4, 8, and 16. Anything else will be rounded up or limited to the nearest supported value. Not all OEMs support this operation.

void control.pause();

Pauses the currently playing content.

void control.play();

Causes play to be called on the OEM-specific player. Only call this method if you called pause, use playlist.start() instead to start initial playback.

void control.rewind(int increment);

Tells the player to rewind the current content at the specified increment if supported by the media player. Supported increments are 2, 4, 8, and 16. Anything else will be rounded up or limited to the nearest supported value. Not all OEMs support this operation.

void control.seek(float offset, Boolean absolute);

Tells the media player to seek to the specified offset in seconds. If true is passed as the absolute parameter, then the offset is considered to be an absolute offset rather than a relative offset from the current playback position.

void control.stop();

Stops playback of the currently playing content.

void control.streamswitch(KONtx.mediaplayer.constants.streamswitch method, Object config);

Tells the media player to perform a stream switch to an alternate stream for the same entry using the specified algorithm identified by the method parameter. The config parameter changes based on the method used. The KONtx.mediaplayer.constants.streamswitch.BANDWIDTH algorithm is used to provided an updated connection bitrate and margin. If you choose this option, the config parameter is an Object with bitrate and margin properties. The config.bitrate property is the bitrate of the consumer’s connection as tested through KONtx.speedtest. The config.margin property is the margin factor to apply to the consumer’s bandwidth. Valid values are between 0 and 1. The config.margin property defaults to 1 or what was previously set if not provided. See the method setConnectionBandwidth() for more details.

The KONtx.mediaplayer.constants.streamswitch.INDEX_CHANGE algorithm is used to increase or decrease the selected stream by a specified amount. If you choose this option, the config parameter is an Object with direction and offset_amount properties. The possible values for config.direction are String values up or down. The default value is down. The config.offset_amount property is the amount to shift up or down. If you provide a config.direction but not a config.offset_amount, then the config.offset_amount is defaulted to 1.

Object getDefaultViewportBounds();

Returns a bounds Object with properties the same as setViewportBounds(). Currently all OEMs return {x:0, y:0, width:1920, height:1080}. The values for the returned Object are subject to change as new OEM platforms are added. Always check for the proper values.

double getMaxBufferSize();

Returns as a double the maxiumum buffer size supported by the device in bytes. The default value is 30 MB.

void initialize();

Initializes the KONtx Media Player. Initialization only needs to happen once, but must be performed before any media playback is started.

KONtx.media.Playlist playlist.get();

Returns the playlist which is currently set on the media player.

void playlist.loadEntry(int entry);

Tells the media player to load and play the specified zero-based entry in the playlist.

void playlist.nextEntry();

Tells the media player to load and play the next entry in the playlist.

void playlist.previousEntry();

Tells the media player to load and play the previous entry in the playlist.

void playlist.set(KONtx.media.Playlist playlist);

Takes a playlist and saves it in the media player for usage.

void playlist.start();

Starts the playlist which is currently set on the media player.

void setConnectionBandwidth(int bitrate, float margin);

Sets the connection bitrate to the specified value. If margin is also provided (defaults to 1), then it is applied to the bitrate before using the bitrate to select a stream. If bitrate == 2000 and margin == 0.8, then that means the KONtx media player will not select any stream greater than 1600. Use this to provide “head room” to help eliminate buffering attempts caused by the consumer using their internet connection temporarily for other things.

void setViewportBounds(int x, int y, int width, int height);

Sets the viewport bounds to the specified values. The parameter x is the horizontal offset of the top left corner of the viewport. The parameter y is the vertical offset of the top left corner of the viewport. The parameter width is the width of the viewport. The parameter height is the height of the viewport. This method also accepts a single parameter in the format of the returned Object from the method getDefaultViewportBounds(), for example:

KONtx.mediaplayer.setViewportBounds(KONtx.mediaplayer.getDefaultViewportBounds());

Table of Contents