Re: mediaplayer for icecast streams?

"Weddle, Ben (Library)" <[email protected]> Thu, 23 Nov 2023 00:14:05 +0000
Newsgroups gmane.comp.audio.icecast.general
Message-ID <SA0PR09MB6043E70640AFA1D7F66F435E98B9A@SA0PR09MB6043.namprd09.prod.outlook.com>
Here's an example with vanilla JS (attached). I had a test file lying around and swapped your info in. You can change setInterval() to fetch as often as you like (1000 = 1 second).

Ben Weddle

-----Original Message-----
From: Icecast <[email protected]> On Behalf Of Railgun
Sent: Wednesday, November 22, 2023 5:49 PM
To: [email protected]
Subject: Re: [Icecast] mediaplayer for icecast streams?

Attention: This email originated from a source external to Metro Government. Please exercise caution when opening any attachments or links from external sources.


you can pull it with jQuery via javascript for example evry 10 seconds, and update the informations you want, at least its the way i do it.

Am 23.11.2023 um 00:13 schrieb Thomas Jensen:

> Thank you, Ben!
>
> I was afraid it would be very complicated to get the information 
> extracted, but it was very simple. My only problem now is to find a 
> way to update the text on the webpage. I was hoping sleep(5) could do 
> the trick, but it does not work.
>
> <?php
> if (1) {
>    $jsonobj=file("http://radio.protestbandet.dk:8000/status-json.xsl");
>    //var_dump($jsonobj);
>    $arr1[]=json_decode($jsonobj[0], true);
>    echo '<strong>'.$arr1[0]['icestats']['source']['title'].'</strong>';
>    sleep(5);
> }
> ?>
>
> Can anyone help?
>
>
> Thanks
>
>
_______________________________________________
Icecast mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/icecast

_______________________________________________
Icecast mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/icecast
nowPlaying.html (text/html, 1.3 KB)
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Testing Now Playing</title>
</head>

<body>

    <div style="display: block;">
        <h1 style="display: inline-block;">Now Playing: </h1>
        <h1 style="display: inline-block; border-style:solid; border-color: brown; border-radius: 50px; padding: 10px;"
            id="title"></h1>
    </div>

    <script>
        async function nowPlaying() {
            let titleElement = document.getElementById('title');
            let notAvailable = "Program Name Not Available";
            try {
                const url = "http://radio.protestbandet.dk:8000/status-json.xsl";
                let response = await fetch(url);
                let icecast = await response.json();
                let nowPlaying = icecast.icestats.source.title;
                if (nowPlaying.trim() == "") {
                    titleElement.innerText = notAvailable
                }
                else {
                    titleElement.innerText = nowPlaying
                }
            }
            catch (whoops) {
                titleElement.innerText = notAvailable;
            }
        }

        nowPlaying()
        setInterval(nowPlaying, 30000)
    </script>

</body>

</html>