This document provides a detailed guide on the structure, configuration, and customization of a single / multi-station radio player built with HTML, CSS, and JavaScript. This player dynamically fetches song information and offers the flexibility to use a local API or a pre-configured web-based API.
This radio player offers a user-friendly interface for enjoying online radio stations. It allows for the addition of multiple stations, each with its own live stream, song information, social media links, and more. Station configuration is done directly within the HTML, simplifying the customization process.
index.html
: Contains the main HTML for the player, including:
<script>
tag.js/main.js
: Houses the JavaScript code that powers the player's functionality, including:
api.php
: (Optional) PHP script acting as a local API to extract metadata from radio streams, providing song information.css/main.min.css
: Defines the visual styling of the player, including layout, colors, and typography.custom.css
: Allows for adding custom styles.assets/
: Folder to store images, icons, and other visual assets.index.html
)Radio stations are configured within a <script>
block in the index.html
file, defining the window.streams.stations
object. Each station is an object with the following properties:
Property | Description |
---|---|
name |
Station name displayed on the interface. |
hash |
Unique identifier for the station. |
description |
Short description of the station. |
logo |
Path to the station logo image file. |
album |
Path to a default "album" image to display before the actual cover art is loaded. |
cover |
Path to the currently playing song's cover art. |
api |
(Optional) URL of the local API (api.php ) configured to fetch station information. This should include the stream_url as a parameter. If left blank, the script will use the pre-configured web API within js/main.js . |
stream_url |
URL of the station's audio stream. |
tv_url |
URL of the station's live video stream (optional). |
server |
Defines the music platform ("spotify" or "itunes") used to fetch additional info (if the corresponding API is in use). |
program |
Object containing information about the current program (optional). |
social |
Object with links to the station's social media profiles (optional). |
apps |
Object with links to download the station's apps (optional). |
Configuration Example:
<script>
window.streams = {
timeRefresh: 10000, // Refresh time in milliseconds
stations: [
{
name: "Example FM",
hash: "examplefm",
description: "The best music!",
logo: "assets/examplefm_logo.png",
album: "assets/default_album.jpg",
cover: "assets/default_album.jpg",
api: "api.php?url=https://example.com/stream", // Local API (optional)
stream_url: "https://example.com/stream",
server: "itunes", // Use iTunes API
social: {
facebook: "https://facebook.com/examplefm",
instagram: "https://instagram.com/examplefm"
}
},
// ... more stations
]
};
</script>
If you choose to use the local API (api.php
), follow these instructions to set it up:
api.php
file, the $allowedUrls
variable should list all allowed stream URLs.getMp3StreamTitle()
: Extracts the song title from the stream metadata.extractArtistAndSong()
: Separates artist and song title.getAlbumArt()
: Fetches album art (currently set up to use the iTunes API). updateHistory()
: Maintains a history of played songs. Note:
If the api
field is left blank in the station configuration, will default to the pre-configured web API. Make sure the web API you are using is functioning and correctly set up within the JavaScript code.
The sections regarding:
css/main.min.css
and custom.css
)assets/
)css/main.min.css
and custom.css
)assets/
)assets
folder with your own to customize the station logo, album art, and icons.api.php
), if used, is configured correctly and accessible on your server.