Automatically get current live stream in iframe player?

I’ll be doing a weekly broadcast to the same livestream Live Input ID. I want an iframe player on a static that I don’t have to edit each week that just shows the current livestream once it starts. Otherwise it just says “No livestream currently in progress” or something like that.

In other words, I want it to work exactly the way it does on the Cloudflare dashboard I see when I click into the live input settings page.

If I could just specify the input id I wanted the livestream for in the iframe code, instead of the video id, it would be just right.

Is that possible?

I just want to get the current livestream playing on my wordpress site without writing a wordpress plugin to use the API or manually editing the page each week.

We will support being able to jump to the latest live video from an Input ID soon. Stay tuned!

If you are familiar with Cloudflare Worker, then you could write a Worker that calls the Stream API and returns or redirects to the latest live video. You can then set the url to the Cloudflare Worker as the iframe src. Here is a code snippet that returns the latest video id given an input id:

let video_list = await fetch("https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/stream/live_inputs/$INPUT_ID/videos", {
  "method": "GET",
  "headers": {
    "Authorization": "Bearer $AUTH_TOKEN"
  }
});
video_list = await video_list.json();
let live_video_id = "INSERT_DEFAULT_VIDEO_ID_IF_NO_LIVE_VIDEO";
for (let one_video of video_list.result) {
    if (one_video.status.state == "live-inprogress") {
       live_video_id = one_video.uid;
        console.log("Found live video: " + one_video.uid);
    }
}
2 Likes

Plus one for this here. I would like to do exactly the same thing. :smiley:

1 Like