Documentation

Radiant Media Player

TypeScript support

How to use Radiant Media Player in a TypeScript project?

With Radiant Media Player 7, it is now possible to use Radiant Media Player in a TypeScript project out of the box

First download Radiant Media Player self-hosted package. In the js/ folder is one file, js/rmp.module.d.ts, that your TypeScript project should automatically recognized. That file adds types declaration for js/rmp.module.js file.

The rmp.module.d.ts file is generated from JavaScript using JSDoc syntax.

Player code example

// import Radiant Media Player as a ES2015 module
import RadiantMP from './radiantmediaplayer/js/rmp.module.js';

const rmp = new RadiantMP('rmp');
const settings = {
  licenseKey: 'your-license-key',
  src: { hls: 'https://your-hls-url' },
  width: 640,
  height: 360,
  pathToRmpFiles: './radiantmediaplayer/'
};
          
const container = document.getElementById('rmp');
if (container) {
  let timeupdateCount = 0;
  container.addEventListener('timeupdate', () => {
    timeupdateCount++;
    if (timeupdateCount === 10) {
      rmp.seekTo(5000);
    }
  });
}
rmp.init(settings);

In the above example you will see that player methods like seekTo are properly recognized by TypeScript and that you can import RadiantMP without having to specify an any type on it.

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

©2015-2021 Radiant Media Player. All rights reserved.