Documentation

Player API

Introduction

Radiant Media Player provides a complete JavaScript API to programmatically control the player, allowing for custom applications to be built on top of the player.

As a start point you may review our implementation example here.

For our ads API please visit this link.

Set up

A basic example of player API usage will look like:

<!-- Include Radiant Media Player JavaScript file in your <body> or <head> -->
<script src="https://cdn.radiantmediatechs.com/rmp/9.14.1/js/rmp.min.js"></script>
<!-- Player container element -->
<div id="rmp"></div>
<!-- Set up player configuration options -->
<script>
// Your streaming source - in this example HLS
const src = {
  hls: 'https://your-hls-url.m3u8'
};
// Your player settings
const settings = {
  licenseKey: 'your-license-key',
  src: src,
  width: 640,
  height: 360,
  contentMetadata: {
    poster: [
      'https://your-poster-url.jpg'
    ]
  }
};
// Reference to player container
const elementID = 'rmp';
// Object creation
const rmp = new RadiantMP(elementID);
rmp.one('ready', () => {
  console.log('player ready');
  // Invoke API methods
  console.log(rmp.getStreamType());
});
rmp.on('playing', () => {
  console.log('player has received playing event');
  rmp.setBitrate(0);
});
// Player initialisation - only after API events are registered
rmp.init(settings);
</script>
<!-- Add a player container with a unique id -->
<div id="rmp"></div>
<!-- Set up async player configuration options -->
<script>
  // Your streaming source - in this example HLS
  const src = {
    hls: 'https://your-hls-url.m3u8'
  };
  // Your player settings
  const settings = {
    licenseKey: 'your-license-key',
    src: src,
    width: 640,
    height: 360, 
    contentMetadata: {
      poster: [
        'https://your-poster-url.jpg'
      ]
    },
    asyncElementID: 'rmp'
  };
  // We push player settings to a global rmpAsyncPlayers variable
  if (typeof window.rmpAsyncPlayers === 'undefined') {
    window.rmpAsyncPlayers = [];
  }
  window.rmpAsyncPlayers.push(settings);
  // we wire our events on player container
  const rmpContainer = document.getElementById(settings.asyncElementID);
  let rmp = null;
  // To get access to the player instance we need to wait for rmpasyncplayerinstanceavailable event (first event to fire in the API)
  rmpContainer.addEventListener('rmpasyncplayerinstanceavailable', () => {
    // player instance is stored in a global array variable rmpAsyncPlayerInstances
    rmp = window.rmpAsyncPlayerInstances[0];
    rmp.one('ready', () => {
      console.log('player ready');
        // Invoke API methods
      console.log(rmp.getStreamType());
    });
    rmp.on('playing', () => {
      console.log('player has received playing event');
      rmp.setBitrate(0);
    });
  });
</script>
<script async src="https://cdn.radiantmediatechs.com/rmp/9.14.1/js/rmp.min.js"></script>

General player API events

Below is a list of events that are dispatched by Radiant Media Player.

You must attach your listener to the player instance before calling the player init method - otherwise you may miss some!

Events are registered with the on method applied to the player instance rmp as shown above. They are unregistered with the off method. Example:

const rmp = new RadiantMP(elementID);
rmp.on('eventA', callbackA);
rmp.init(settings);

You can register multiple events for the same callback, example:

const rmp = new RadiantMP(elementID);
rmp.on('eventA eventB eventC', callbackA);
rmp.init(settings);

You can access the name of the event being fired:

function callbackA (event) {
  console.log(event.type); // name of the event being fired
}
const rmp = new RadiantMP(elementID);
rmp.on('eventA eventB eventC', callbackA);
rmp.init(settings);

You can unregister an event with the off method:

const rmp = new RadiantMP(elementID);
rmp.off('eventA', callbackA);
rmp.init(settings);

You can unregister multiple events for the same callback as well:

const rmp = new RadiantMP(elementID);
rmp.off('eventA eventB eventC', callbackA);
rmp.init(settings);

You can also register an event where the callback is only executed once:

const rmp = new RadiantMP(elementID);
rmp.one('eventA', callbackA);
rmp.init(settings);

As with the on method you can register multiple events for the same callback with the one method.

General player events

In this section the element refers to HTML5 media element and user agent to the browser or WebView rendering the media.

ready

Fire when the player is ready to receive calls from the API and is appended to DOM

play

Fires when the element is no longer paused. Fired after the play() method has returned, or when the autoplay attribute has caused playback to begin

pause

Fires when the element has been paused

timeupdate

Fires when the current playback position changed as part of normal playback or in an especially interesting way, for example discontinuously

ended

playback has stopped because the end of the media resource was reached

loadstart

Fires when the user agent begins looking for media data, as part of the resource selection algorithm

loadedmetadata

Fires when the user agent has just determined the duration and dimensions of the media resource and the text tracks are ready

durationchange

Fires when the media duration has just been updated

loadeddata

Fires when the user agent can render the media data at the current playback position for the first time

progress

Fires when the user agent is fetching media data

canplay

Fires whenthe user agent can resume playback of the media data, but estimates that if playback were to be started now, the media resource could not be rendered at the current playback rate up to its end without having to stop for further buffering of content.

canplaythrough

Fires when the user agent estimates that if playback were to be started now, the media resource could be rendered at the current playback rate all the way to its end without having to stop for further buffering

waiting

Fires when playback has stopped because the next frame is not available, but the user agent expects that frame to become available in due course. For buffer information use bufferstalled event instead.

playing

Fires when playback is ready to start after having been paused or delayed due to lack of media data. For buffer information use buffernotstalledanymore event instead.

seeking

Fires when the player starts seeking to a new position in the media

seeked

Fires when the player is finished seeking to a new position in the media

stopcompleted

Fires when stop API method has completed

loop

Fires when a loop event happens (on-demand video finishes and automatically restarts)

firstframe

Fires when first frame of content or pre-roll ad (whichever comes first) is shown in the player

startuptimeavailable

Fires when startup time analytics data is available

htmlmediaelementappendedtodom

Fires when the HTML5 media element (video or audio tag) has been appended to DOM after init has been called on player. This event fires before ready event. The HTML5 media element can be accessed through the getHtmlMediaElement API method.

rmpasyncplayerinstanceavailable

Fires when the Radiant Media Player instance is created when the player core library is async loaded. See usage example here.

General player API read-only methods

Unless stated otherwise the following API read-only methods must be queried after the ready API event has fired.

General player API read-only methods

getReady()

rmp.getReady();

This method returns a Boolean indicating if the player is ready or not.

getPlayerVersion()

rmp.getPlayerVersion();

This method returns a String representing the current player version (MAJOR.MINOR.PATCH as in Semantic Versioning).

getHtmlMediaElement()

rmp.getHtmlMediaElement();

This method returns a HTMLMediaElement, the HTML5 video or audio tag used by Radiant Media Player. This method can be queried when the htmlmediaelementappendedtodom event fires.

getPaused()

rmp.getPaused();

This method returns a Boolean representing the state of the media content either paused or playing. true means the content on stage is currently paused.

getCurrentTime()

rmp.getCurrentTime();

This method returns a Number expressed in milliseconds representing the current playback position in the media content. -1 is returned in case the value is not available.

getCurrentTimeBeforeSeek()

rmp.getCurrentTimeBeforeSeek();

This method returns a Number expressed in milliseconds representing the current playback position in the media content before seeking. This method should be invoked when seeking event fires. -1 is returned in case the value is not available.

getDuration()

rmp.getDuration();

This method returns a Number expressed in milliseconds representing the total duration of the media content. -1 is returned in case the value is not available. Note that on some mobile devices the duration may only be available after a successful play event.

getStreamType()

rmp.getStreamType();

This method returns a String representing the currently loaded streaming protocol: 'hls', 'dash', 'mp4', 'webm', 'm4a', 'mp3', 'ogg', 'outstream', 'nosupport'.

getStreamMode()

rmp.getStreamMode();

This getter returns a String stating the current streaming mode. Possible values are: 'livedvr', 'voddvr', 'live', 'vod', 'unresolved'.

getLoop()

rmp.getLoop();

This method returns a Boolean stating if the player is in loop mode or not. true means the player automatically jumps back to start and continue playback when content completes.

getControls()

rmp.getControls();

This method returns a Boolean stating if the default player controls are available or not. true means the default player controls are available.

getControlsVisible()

rmp.getControlsVisible();

This method returns a Boolean stating if the default player controls are currently visible or not. true means the default player controls are visible.

getAdUI()

rmp.getAdUI();

This method returns a Boolean stating if the player advertisement UI is currently shown or hidden. true means the advertisement UI is visible.

getWaitingUI()

rmp.getWaitingUI();

This method returns a Boolean stating if the player is in waiting mode while displaying its waiting UI. true means the player is in waiting mode.

getContentMetadata()

rmp.getContentMetadata();

This method returns Object representing the content metadata. See here for the contentMetadata setting.

getAppName()

rmp.getAppName();

This method returns a String with the current appName set for the player. An empty string is returned if this value is not available.

getPreload()

rmp.getPreload();

This method returns a String representing the preload mode used for player start up. This method is only available after ready event has fired, '' is returned otherwise.

getBandwidthEstimate()

rmp.getBandwidthEstimate();

This method returns a Number representing the real-time available device bandwidth captured by the player in bps. -1 is returned if this information is not available.

getRatio()

rmp.getRatio();

This method returns an Object representing the player ratio and media ratio (for content currently being displayed). Example:

{ 
  player: 1.7777777778,
  media: 1.7777777778
}

Player API methods

The following methods must be called after the ready event has fired.

play() asynchronous

rmp.play();

When invoked, this method will cause the player to start playback or resume it if it was paused. playing event will fire when playback starts/resumes.
On mobile devices this method must be called within a user interaction callback (touchend event generally) to start initial playback.
Do not use play method to force or emulate autoplay - instead use autoplay setting as described here.

pause()

rmp.pause();

When invoked, this method will cause the player to pause playback.

stop() asynchronous

rmp.stop();

When invoked, this method will cause the player to pause playback returning its playhead to 0 (for on-demand content) and show the current poster. If a video ad is on stage the player will first discard the ad and then reach the stop state. stopcompleted event will fire when stop method has completed.

seekTo(ms) asynchronous

rmp.seekTo(5000);

When invoked, this method will cause the player to seek to the value indicated as parameter. Parameter value is a Number expressed in milliseconds. Note that milliseconds accurate seeking is not guaranteed as it depends on the browser implementation of the HTML5 media currentTime property. Most of the time you can expect a 100 ms precision with modern browsers. This method will have no effect if an ad is playing on stage or with a live stream. seeked event will fire when seekTo method has completed.

setLoop(loop)

rmp.setLoop(true);

When invoked, this method will change the player loop mode. Parameter value is a Boolean. When set to true it will enabled loop mode. When set to false it will disable it.

setContentMetadata(contentMetadata)

rmp.setContentMetadata({
  title: 'My content title', 
  description: 'My content description',
  poster: [
    'https://dummyimage.com/1xDPR',
    'https://dummyimage.com/2xDPR'
  ]
});

When invoked, this method updates the current content metadata. Input must be a Object. This can be useful when using the setSrc API method to update metadata as player source changes.

showPoster()

rmp.showPoster();

This methods causes the current player poster to be displayed on stage.

hidePoster()

rmp.hidePoster();

This methods causes the current player poster to be hidden from the stage.

setControls(controls)

rmp.setControls(false);

This method permanently hide player controls (input setting set to false) or enable player controls (input setting set to true). Input parameter must be a boolean.

setControlsVisible(controls)

rmp.setControlsVisible(false);

This method fades in (input setting set to true) or fades out (input setting set to false) player controls. Input parameter must be a boolean.

setAdUI(adUI)

rmp.setAdUI(false);

This method hides (input parameter set to false) or shows (input parameter set to true) the advertisement UI - overriding the default player controls. Input parameter must be a boolean.

setWaitingUI(adUI)

rmp.setWaitingUI(true);

This method hides (input parameter set to false) or shows (input parameter set to true) the player waiting UI. Note that the player may internally still decides to hide or show the waiting UI. Input parameter must be a boolean.

fastForward()

rmp.fastForward();

Calling this method will set the player in fast-forward mode. Note that there are 3 fast-forward speeds. So calling fastForward twice will cause the player to enter x2 fast-forward mode. Call play() to exit fast-forward mode. Also note that fastForward UI is only available with our TV player, but the fastForward API can be used with the general player as well.

fastRewind()

rmp.fastRewind();

Calling this method will set the player in fast-rewind mode. Note that there are 3 fast-rewind speeds. So calling fastRewind twice will cause the player to enter x2 fast-rewind mode. Call play() to exit fast-rewind mode. Also note that fastRewind UI is only available with our TV player, but the fastRewind API can be used with the general player as well.

Environment detection API

getEnvironment()

rmp.getEnvironment();

This method returns an Object representing the current environment (e.g. feature detection & type of device) in which Radiant Media Player is rendered. Example to detect a mobile device:

const env = rmp.getEnvironment();
const isMobile = env.isMobile;
const isAndroid = env.isAndroid[0];
const isIos = env.isIos[0];
const isMacosSafari = env.isMacosSafari[0];

See a full example of output here. This is an advanced method which is mainly used by the player internally and provided as indication as you may see it in some of our code examples. Note that this method can be used before calling init on player.

Volume API

Volume API events

volumechange

Fires when the player changes its volume

Volume API methods

getVolume()

rmp.getVolume();

This method returns a Number representing the current player volume (between 0 and 1). -1 is returned if this value is not available.

getMute()

rmp.getMute();

This method returns a Boolean stating if the player is currently muted or not. true means player is muted.

setVolume(volume)

rmp.setVolume(0.8);

When invoked, this method will change the volume level of the player audio track. Parameter value is a Number ranging from 0 to 1.
An example of implementation of the mute/volume API can be viewed here.
Do not use the setVolume API method to set initial player volume when ready event fires - instead use initialVolume player setting.
On iOS, volume cannot be set/get through JavaScript (OS-level limitation). You can use setMute/getMute as an alternative.

setMute(muted)

rmp.setMute(true);

When invoked, this method will cause the player to enter or exit mute mode based on the input parameter. Parameter should be a Boolean with true meaning the mute mode should be engaged and false the mute mode should be disengaged.
An example of implementation of the mute/volume API can be viewed here.

Fullscreen API

Fullscreen API events

enterfullscreen

Fires when the player enters fullscreen mode

exitfullscreen

Fires when the player enters exitfullscreen mode

warning

with code 1003 will fire when a fullscreen error is detected

Fullscreen API methods

getFullscreen()

rmp.getFullscreen();

This method returns a String representing the URI for the current player media source.

setFullscreen(fs) asynchronous

rmp.setFullscreen(true);

When invoked, this method will order the player to enter or exit fullscreen based on input parameter. Input parameter must be a Boolean. enterfullscreen, or exitfullscreen or warning (with code 1003) event will fire when this method has completed.
The player may only enter fullscreen through the setFullscreen API method as a result of a valid user interaction. Modern browsers generally block entering full screen programmatically.

Sizing API

Sizing API event

resize

Fires when player is resizing

Sizing API methods

getPlayerWidth()

rmp.getPlayerWidth();

This method returns a Number representing the current width in pixels of the player.

getPlayerHeight()

rmp.getPlayerHeight();

This method returns a Number representing the current height in pixels of the player.

resize() asynchronous

rmp.resize();

When invoked, this method will force the player to resize itself based on its new context dimension. resize event will fire when this method has completed.

setPlayerSize(width, height) asynchronous

rmp.setPlayerSize(960, 540);

When invoked, this method will dynamically resize the player to the provided width and height parameters. The width and height parameters must be Number representing pixels. This method will have no effect with autoHeightMode and iframeMode player settings or when player is in fullscreen. resize event will fire when this method has completed.

Buffer API

An example of implementation of the buffer API can be viewed here.

Buffer API events

bufferstalled

Fires when current buffer is empty - media playback is stopped until enough buffer has been downloaded to resume playback

buffernotstalledanymore

Fires when player has resumed playback after a bufferstalled event (e.g. it exits buffering state)

Buffer API method

getBufferLength(type)

rmp.getBufferLength('ahead');
rmp.getBufferLength('behind');

This method returns a Number expressed in milliseconds representing the current player buffer. It takes an input String parameter which must either be 'ahead' (this would return the buffer ahead value) or 'behind' (this would return the buffer behind value, also known as back-buffer). -1 is returned in case this value is not available. This works for HLS, DASH or progressive download.

Quality API

An example of implementation of the quality API can be viewed here.

Quality API events

levelswitching

Fires when the player is starting to change quality - works for HLS, DASH and progressive download in manual or automatic ABR mode

levelswitched

Fires when the player has changed quality - works for HLS, DASH and progressive download in manual or automatic ABR mode

Quality API methods

setBitrate(index)

rmp.setBitrate(0);

This method allows to set the current rendition for the player based on an index value. Input parameter must be a Number. For HLS and DASH streaming, index at 0 will cause the player to play the lowest rendition available. This method has no effect if called when a linear ad is playing on stage or if input index is out of bound. See getBitrates method to get information about available renditions and to determine which rendition is currently active.

This method is available HLS, DASH and progressive download.

For HLS and DASH streaming, rmp.setBitrate(-1) will restore the player to its 'auto' ABR mode.

For native HLS (default on iOS and macOS Safari) this method will have no effect.

getBitrates()

rmp.getBitrates();

This method returns an Array of Object representing available renditions for the current streaming source. This method is available for HLS, DASH and progressive download. Each element of the returned Array is an Object holding information about the current rendition. The Object is as follows:

{
  active: true, // Boolean: if the current audio track active or not
  audioCodec: "mp4a.40.2", // String: the audio codec name when available
  bitrate: 727221, // Number: the bandwidth in bps required to the play the current rendition
  height: 360, // Number: the height in px of the rendition (not available for audio-only feed)
  id: 0, // Number: the bitrate id
  videoCodec: "avc1.4d401e", // String: the video codec name when available (not available for audio-only feed)
  width: 640 // Number: the width in px of the rendition (not available for audio-only feed)
}

The active property of each rendition can be queried in order to know which rendition is currently played in the player.

For progressive download only the active and id properties of a rendition object will be available.

For native HLS (default on iOS and macOS Safari) this method will return

[{
  active: false,
  audioCodec: '',
  bitrate: -1,
  height: -1,
  id: -1,
  videoCodec: '',
  width: -1
}]

For audio-only streams this method should be used to get the different renditions of a stream with the same language information. The getAudioTracks method should only be used to get information about audio tracks that have different language data.

getCurrentBitrateIndex()

rmp.getCurrentBitrateIndex();

This method returns a Number representing the index of the rendition currently being played within the player. -2 is returned if this information is not available. This method works for MSE-based HLS, DASH and progressive download. For HLS or DASH -1 is returned if the player is in ABR auto-mode.

getAbrAutoMode()

rmp.getAbrAutoMode();

This method returns a Boolean stating if the player is in ABR auto mode (true) or not (false).

Audio tracks API

An example of Audio tracks API implementation can be viewed here.

Audio tracks API events

audiotrackswitching

Fires when an audio track switch is requested

audiotrackswitched

Fires when an audio track switch completes

Audio tracks API methods

getAudioTracks()

rmp.getAudioTracks();

This method returns an Array of Object representing the loaded audio tracks for the current HLS or DASH stream. For HLS only independent audio tracks (e.g. with a dedicated .m3u8 rendition) will be returned. Each element of the returned Array is an Object holding details about the related audio track. The Object is as follows:

{
  active: true, // Boolean: if the current audio track active or not
  id: 0, // Number: the audio track id
  language: "en" // String: language code for the audio track
}

The id property from the Object of each Array item can be used with the setAudioTrack method to select a specific audio track.

With HLS the audio track API is not available on iOS or macOS Safari as Apple does not currently provide the required MSE API to enable this feature. With HLS on iOS or macOS Safari audio tracks can be selected when the player is in fullscreen mode (using the Apple provided tracks menu).

setAudioTrack(id)

rmp.setAudioTrack(1);

This method set the current HLS or DASH audio track being read by the player. The id (Number) parameter represents the id of the audio track within the available audio tracks (see getAudioTracks method).

Changing source API

An example of implementation of the src API can be viewed here.

src API events

srcchanging

Fires when the player starts changing its source media URI

srcchanged

Fires when the player has finished changing its source media URI

error

Fires when the player was not able to change source due to a fatal error when trying to load the new source - see error management page to get details about the error - upon an error event, the setSrc method can still be invoked with a new source to attempt recovery from the error

src API methods

getSrc()

rmp.getSrc();

This method returns a String representing the URI for the current player media source.

setSrc(newSourceObject) asynchronous

const newSourceObject = {
  hls: 'https://your-hls-url.m3u8',
  mp4: [
    'https://your-mp4-sd-url.mp4',
    'https://your-mp4-hd-url.mp4'
  ]
};
rmp.setSrc(newSourceObject);

This method updates the current player media source with the provided Object input parameter. When setSrc is called with a valid input Object parameter, the player will clear its current buffer, load the new media source and updates its UI (including bitrate informations, audio-tracks and in-manifest text tracks). When source change has completed the srcchanged event fires. Also see the srcChangeAutoplay player setting.

The setSrc method can also be used for DRM use-case, see here for additional details

setSrc(newSourceObject, newBackupSourceObject) asynchronous

const newSourceObject = {
  hls: 'https://your-hls-url.m3u8',
  mp4: [
    'https://your-mp4-sd-url.mp4',
    'https://your-mp4-hd-url.mp4'
  ]
};
const newBackupSourceObject = [{
  hls: 'https://your-backup-hls-url.m3u8',
  mp4: [
    'https://your-backup-mp4-sd-url.mp4',
    'https://your-backup-mp4-hd-url.mp4'
  ]
}];
rmp.setSrc(newSourceObject, newBackupSourceObject);

The setSrc API method described above can also be used in conjunction to our fallback streaming URL feature

isChangingSrc()

rmp.isChangingSrc();

Since setSrc runs asynchronously you may want to check if it is running before usage. This method returns a Boolean stating if setSrc is currently running or not. If setSrc is running, invoking setSrc will have no effect and a 1005 warning event will fire.

Player destroying API

An example of implementation of the destroy API can be viewed here.

When you are done using the player on your page and want to release memory/CPU resources you can call the destroy API method.

While it is possible to use destroy to update an existing player instance with a new one, we generally recommend using setSrc or other API methods described in our documentation to update your player instance.

destroy API events

destroycompleted

Fires when the player has finished destroying its instance (using the destroy method)

destroy API methods

destroy() asynchronous

rmp.destroy();

This method destroys the current player instance, removing listeners and emptying player buffer. The player container is thus ready for removal from DOM when destroycompleted event fires. If destroy is running, invoking destroy will have no effect and a 1004 warning event will fire.

HLS API with hls.js (default)

The following HLS API events and methods are only available when streaming HLS content when the hlsEngine setting is set to 'hlsjs' (default). They do not apply to MPEG-DASH content or HLS content when the hlsEngine setting is set to 'shakaplayer' or when HLS content is displayed with native rendering (iOS or iPadOS where Media Source Extensions are not available).

Player API events

hlsinstancecreated

Fires when the hls.js instance has been created

hlsmanifestloaded

Fires when the player has finished loading the main HLS manifest

hlsmanifestparsed

Fires when the player has finished parsing the main HLS manifest

hlslevelloaded

Fires when the player has finished loading a level

hlsfragmentloaded

Fires when the player has finished loading a fragment

hlsfragmentbeingplayedchanged

Fires when the fragment being rendered within the player changes

hlssubtitletrackswitch

Fires when a subtitle track switch occurs

The above events will not fire when native HLS is used by the player (e.g. on iOS & macOS Safari)

API methods

getHlsJSInstance()

rmp.getHlsJSInstance();

This method returns an Object representing the hls.js instance created by the player. This instance is available when the hlsinstancecreated event fires.

getHlsManifestData()

rmp.getHlsManifestData();

This method returns an Object representing the HLS manifest data. It can be queried when the hlsmanifestloaded event fires.

{
  levels: [ Object ], // Array of levels/rendition data
  audioTracks: [ Object ], // Array of audio tracks data
  subtitles: [ Object ], // Array of subtitles data
  captions: [ Object ] // Array of captions data
}

A level Object should look like:

{
  url: 'http://levelURL.com', // level URL
  bitrate: 246440, // level bitrate in bps
  name: "240p", // level name
  codecs: "mp4a.40.5,avc1.42000d", // level codecs (video,audio)
  width: 320, // level width
  height: 180, // level height
}

getHlsLevelData()

rmp.getHlsLevelData();

This method returns an Object representing the currently loaded level. It can be queried when the hlslevelloaded event fires. The returned Object is as follows:

{
  version: 3, // HLS version
  type: 'VOD', // playlist type
  startSN: 0, // start sequence number
  endSN: 50, // end sequence number
  totalduration: 510, // level total duration
  targetduration: 10, // level fragment target duration
  fragments: Array(51), // array of fragments info
  live: false // is this level a live playlist or not
}

getHlsFragmentData()

rmp.getHlsFragmentData();

This method returns an Object representing the currently loaded fragment. It can be queried when the hlsfragmentloaded event fires. The returned Object is as follows:

{
  duration: 10, // fragment duration
  level: 3, // level identifier
  sn: 35, // fragment sequence number
  start: 30, // fragment start offset
  url: 'http://fragURL.com' // fragment URL
}

getHlsFragmentBeingPlayedData()

rmp.getHlsFragmentBeingPlayedData();

This method returns an Object representing the fragment currently being rendered by the player. This is generally used in conjunction with the hlsfragmentbeingplayedchanged event. The returned Object is of the same format as with the getHlsFragmentData method.

getHlsSessionData()

rmp.getHlsSessionData();

This method returns an Object representing the #EXT-X-SESSION-DATA read by the player in the HLS manifest. This is avilable with the hlsmanifestloaded event. Example of output:

{ 
  com.apple.hls.chapters: { 
    DATA-ID: "com.apple.hls.chapters", 
    URI: "https://www.rmp-streaming.com/media/hls/EXT-X-SESSION-DATA/chapters.json"
  },
  com.apple.hls.director: { 
    DATA-ID: "com.apple.hls.director", 
    VALUE: "Martin Director"
  }
}

hlsStartLoad()

rmp.hlsStartLoad();

This method allows to start/restart the playlist/fragment loading process. This method should only be queried after the hlsmanifestparsed event has fired.

hlsStopLoad()

rmp.hlsStopLoad();

This method allows to stop the playlist/fragment loading process. This can be useful to better manage the HLS loading mechanism and to save bandwidth when the loading of new fragments is not needed anymore. When the playlist/fragment loading process has been stopped it can be resumed with the hlsStartLoad method. When hlsStopLoad is requested be mindful to always call hlsStartLoad when the viewer requests playback again so as to resume the fragment loading process - otherwise the player may stop working as expected due to the lack of new fragments for rendering.

MPEG-DASH API

The following API events and methods are only available when streaming MPEG-DASH content or HLS content when the hlsEngine setting is set to 'shakaplayer'. They do not apply to HLS content when the hlsEngine setting is set to 'hlsjs' (default) or when HLS content is displayed with native rendering (iOS or iPadOS where Media Source Extensions are not available).

Player API events

shakainstancecreated

Fires when the Shaka player instance has been created

shakamanifestparsed

Fres when Shaka player has finished parsing the DASH manifest

shakatrackschanged

Fires when the list of tracks changes - for example, this will happen when changing periods or when track restrictionschange

Player API methods

getShakaPlayerInstance()

rmp.getShakaPlayerInstance();

This method returns an Object representing the Shaka player instance created by the player. This instance is available when the shakainstancecreated event fires.

Accessing the HTMLMediaElement, hls.js or Shaka Player instances

Some advanced use-cases may require access to the HTMLMediaElement, hls.js or Shaka Player instances that Radiant Media Player dynamically creates when needed. The example below show how this can be achieved through our player API:

const elementID = 'rmp';
const rmp = new RadiantMP(elementID);
// We wire our events before calling init
rmp.one('hlsinstancecreated', () => {
  const hlsJSInstance = rmp.getHlsJSInstance();
  console.log(hlsJSInstance);
});
rmp.one('shakainstancecreated', () => {
  const shakaPlayerInstance = rmp.getShakaPlayerInstance();
  console.log(shakaPlayerInstance);
});
// this is the recommended method to access the HTML5 media element 
// dynamically created by Radiant Media Player
rmp.one('htmlmediaelementappendedtodom', () => {
  const videoTag = rmp.getHtmlMediaElement()
  console.log(videoTag);
});
// as an alternative you may use the following to access the HTML5 media element
const videoTagInterval = setInterval(() => {
  const rmpVideoTags = document.getElementsByClassName('rmp-video');
  if (rmpVideoTags.length > 0) {
    clearInterval(videoTagInterval);
    const videoTag = rmpVideoTags[0];
    console.log(videoTag);
  }
}, 100);
rmp.init(settings);
  • The hls.js instance corresponds to const hls = new Hls(config); as described here.
  • The Shaka Player instance corresponds to const player = new shaka.Player(video); as described here.

API usage examples

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License.

©2015-2024 Radiant Media Player. All Rights Reserved.