Radio Software | Information | How to | Live Radio Online

Featured

How i can make "Now Playing"?

Creating a "Now Playing" system is a fantastic project. The approach you take depends heavily on your starting point and technical comfort level.

Here’s a breakdown of the most common methods, from the simplest to the most advanced.

 

1. For a Web Stream (Shoutcast/Icecast) - The Technical Method

This is the most common scenario. You are running a Shoutcast or Icecast server, and you want to display the currently playing song on a website.

How it Works:

The audio streaming server (like Icecast) broadcasts not only the audio data but also a packet of metadata (the artist and title) every so often, often called ICY Metadata. Your website needs a way to grab this metadata and display it.

Here are two primary ways to do it:

A. Using a Pre-built Player (Easiest)

Many modern web players handle metadata extraction automatically.

  • jPlayer (jQuery): A popular, customizable HTML5 audio player that can parse and display Icecast metadata.

  • Howler.js: A powerful JavaScript library for audio that can also handle streaming metadata.

  • RadioDroid Web Player: A simple, pre-built iframe player designed specifically for this.

Example with Simple HTML (<audio> tag):
Some browsers can natively display the metadata in the default player, but you have no control over the styling.

<audio controls>
  <source src="http://yourradiostation.com:8000/stream" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

B. Writing a Simple Backend Script (More Control)

For full control, you need a small script on your web server that fetches the metadata from the stream. This is necessary because modern browsers often block direct JavaScript access to the raw stream metadata due to CORS policies.

The Classic Method:

  1. Server-Side Script (PHP/Python/Node.js): This script connects to your radio stream, reads the metadata, and makes it available as a simple text or JSON file.

  2. JavaScript on your Website: This JavaScript on your page regularly (e.g., every 10 seconds) fetches the data from your server-side script and updates the HTML.

Step-by-Step Overview:

  1. Create a "get_song.php" (or similar) script on your web server:

    <?php
    // Configure the stream URL
    $stream_url = 'http://yourradiostation.com:8000/stream';
    
    // Set a long timeout
    $ctx = stream_context_create(['http' => ['timeout' => 5]]);
    
    // Open the stream and read the ICY metadata
    $stream = fopen($stream_url, 'r', false, $ctx);
    
    if ($stream) {
        // Get the headers to find the 'icy-name' or 'icy-genre'
        $meta_data = stream_get_meta_data($stream);
        
        // Loop through headers to find the current song
        foreach ($meta_data['wrapper_data'] as $header) {
            // Look for the specific metadata header
            if (strpos(strtolower($header), 'icy-description:') !== false) {
                // Some streams use this
                $now_playing = substr($header, 17);
            }
            if (strpos(strtolower($header), 'icy-name:') !== false) {
                // This often contains the song info
                $now_playing = substr($header, 9);
            }
        }
        fclose($stream);
        
        // If we found something, output it, otherwise show a default message
        echo htmlspecialchars($now_playing ? $now_playing : "Station Name - No Data");
    } else {
        echo "Could not connect to stream.";
    }
    ?>

     

Note: This is a basic example. Parsing metadata reliably can be more complex.

2. Create a "nowplaying.js" file on your website:
This script uses fetch to call your PHP script and update the page.

function updateNowPlaying() {
    fetch('get_song.php')
        .then(response => response.text())
        .then(data => {
            document.getElementById('now-playing').innerText = data;
        })
        .catch(err => console.error('Error fetching song data:', err));
}

// Update immediately when the page loads
updateNowPlaying();

// Then update every 15 seconds
setInterval(updateNowPlaying, 15000);

3. Add an element to your HTML:

<div>Now Playing: <span id="now-playing">Loading...</span></div>

 

2. For Local Music (MP3s, etc.) - Using Music Player Software

If you are playing music from files on your computer (e.g., for a live DJ mix or a personal stream), the software you use likely has a feature to export "Now Playing" info.

  • BUTT (Broadcast Using This Tool): A simple streaming tool that can write the current song to a text file. You can then have a website script read that file.

  • SAM Broadcaster / RadioDJ / VirtualDJ: These professional programs have advanced, built-in tools for generating "Now Playing" HTML pages, XML feeds, or writing to a database. This is the easiest and most robust method for serious broadcasting.

  • MusicBee / iTunes: Some media players have plugins or scripts that can export the currently playing track to a file.

The Process:

  1. Configure your broadcasting software to write the current song to a .txt file on your server.

  2. Write a simple PHP/JavaScript combo (as shown above) that reads the contents of that text file instead of connecting to the stream directly.

3. Using a Dedicated Service (Simplest)

If you don't want to handle any coding, several services integrate directly with popular broadcasting software.

  • Radio.co: Offers a full hosting solution with an embeddable player that automatically shows "Now Playing".

  • Centovacast: Another popular hosting control panel that generates "Now Playing" widgets for your site.

  • AzuraCast: If you are self-hosting with AzuraCast, it provides a full API and pre-built widgets to show current song data on any website.

Summary: What's Your Starting Point?

  • "I have a stream URL and a website." → Use the PHP/JavaScript backend method.

  • "I'm using software to play music from my computer." → Check your software's settings for a "now playing" export feature (text file, XML).

  • "I want the absolute easiest, no-code solution." → Use a pre-built player like jPlayer or a hosted service like Radio.co.

Read More:

Tags Cloud

Live Radio Online