Skip to content
Advertisement

HLS/m3u8 stream checker for a LIVE badge/image

Hey everybody how are you doing.

I have a small but for me a headache question. In short. I want to show a ”LIVE” badge/image if a HLS/m3u8 stream is active.

If somebody know’s how to achieve this, i would really appreciate it. Tried to google it but im clueless when it comes to implementing ”custom” code. It’s for a wordpress website.

i tried to work with this snippet but unfortunately it is not working for me.

<?php

    ini_set('default_socket_timeout', 1);

    if(!$fp = @fopen("https://example.com/hls/mainprogram.m3u8?src=1&rate=1", "r")) {
        echo "no stream";
    } else {
        echo "streaming";
        fclose($fp);
    }

?>

Kind regards. (First time of me posting here. if i did something wrong let me know!)

Advertisement

Answer

Asked Def Forge if a status-200 checker would be sufficient and aparantly thats enough. I reccommended Axios but i think just “fetch” would be enough.

fetch("https://example.com/hls/mainprogram.m3u8?src=1&rate=1").then(function(response) {
  console.log(response.status)
}).then(function(data) {
  console.log(data);
}).catch(function() {
  console.log("Failure");
});
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement