Documentation

Asynchronous player loading

Why Asynchronous Loading?

Asynchronous code loading and execution can bring great benefits to a Web App including:

  • Non-Blocking: Prevents the main thread from being held up by time-intensive tasks.
  • Better Performance: Ideal for handling multiple tasks simultaneously, such as API calls.
  • Improved User Experience: Keeps applications responsive while background tasks are being executed.
  • Scalable Solutions: Suitable for real time apps which include chat applications and live updates.

Radiant Media Player relies internally on Promises and Async/Await concepts and many player API calls are asynchronous in nature. In this documentation we will review how to asynchronously load player library.

Code Example

<div id="rmp"></div>
<script>
  const script = document.createElement('script');
  script.async = true;
  // If video is the main content on your page you can use fetchpriority = 'high'
  script.fetchpriority = 'high';
  script.addEventListener('load', () => {
    // Radiant Media Player library has successfully loaded - init
    const src = {
      hls: 'https://your-hls-url.m3u8'
    };
    const settings = {
      licenseKey: 'your-license-key',
      src,
      width: 640,
      height: 360
    };
    const elementID = 'rmp';
    const rmp = new RadiantMP(elementID);

    async function initRmpPlayer() {
      try {
        await rmp.init(settings);
      } catch (error) {
        console.error('error during player initialisation', error);
      }
    }
    initRmpPlayer();
  });
  script.addEventListener('error', () => {
    // Radiant Media Player library failed at loading - this should not be happening often
    console.error('Failed to load script:', script.src);
  });
  script.src = 'https://cdn.radiantmediatechs.com/rmp/10.1.1/js/rmp.min.js';
  document.body.appendChild(script);
</script>
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License.

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