muxinc / videojs-mux-kit

MIT License
33 stars 11 forks source link

How to handle live stream not started error? #106

Closed turivishal closed 1 year ago

turivishal commented 1 year ago

I am integrating the player into html-js static site, below is my code:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Static Template</title>
    <script src="https://cdn.jsdelivr.net/npm/@mux/videojs-kit@latest/dist/index.js"></script>
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@mux/videojs-kit@latest/dist/index.css"
    />
  </head>
  <body>
    <video
      id="my-player"
      class="video-js vjs-16-9"
      controls
      preload="none"
      width="100%"
    >
      <source
        src="8fCGUaEp3DcVM3BlizlfOBQeev02TgzFE016RcdedReBo"
        type="video/mux"
      />
    </video>

    <script>
      videojs("my-player", {
        plugins: {
          httpSourceSelector: {},
          mux: {
            debug: true,
            automaticErrorTracking: false,
            data: {
              video_title: "Example Title"
            }
          }
        }
      });
    </script>
  </body>
</html>

The streaming is not started yet, It shows the "A network error caused the media download to fail part-way." error in the player, is there any way to handle this error and show a preview image or wait for the host message or something?

image

Codesandbox link: https://codesandbox.io/s/mux-videojs-player-error-tsdm72

dylanjha commented 1 year ago

Hi @turivishal thanks for opening this issue.

For live streams, you'll have to wait until the stream is "active". Before "active" the playback ID will not be able to used in a player.

You can monitor the live stream status via webhooks or with GET /video/v1/live-streams/{LIVE_STREAM_ID} on your server. Webhooks is preferred to avoid API request rate limits.

Let me know if this helps

turivishal commented 1 year ago

Thank you for your reply, It makes sense.