Stream SDK JavaScript Ready Event/Callback

Is there a “ready” event or callback available from the Stream SDK?

I am dynamically adding the script to the DOM and need to wait for it to be ready. Trying to init a video is causing undefined errors (“Uncaught ReferenceError: Stream is not defined”). Using timers is not ideal.

Additionally for reference, the YouTube player API has a callback method when it has been loaded.

onYouTubeIframeAPIReady – The API will call this function when the page has finished downloading the JavaScript for the player API, which enables you to then use the API on your page. Thus, this function might create the player objects that you want to display when the page loads.

https://embed.videodelivery.net/embed/sdk.latest.js

2 Likes

Hello there! Thanks for writing in!

The script’s load event should work as the Stream function is defined synchronously upon loading. The player API returned from the Stream function will queue commands and property changes that happen before the iframe has loaded, and flush them when the player in the iframe is ready for them.

Here’s an example snippet for reference:

      const script = document.createElement("script")
      script.src =
        "https://embed.videodelivery.net/embed/sdk.latest.js"
      script.addEventListener("load", () => {
        console.log(Stream)
        const player = Stream(
          document.querySelector("iframe"),
        )
        player.volume = 0.5
        player.play()
      })
      document.head.appendChild(script)

Hope this helps! :smiley:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.