Three ways to build it
Pick the version that matches how much control you want over the page. All three point at the same stream; they differ in what happens when the visitor taps.
| Build | What the tap does | Good for | Watch out for |
|---|---|---|---|
| A plain link | Opens your station page or pop-out player in a new tab | Any site builder, menus, email footers | Audio lives in another tab; visitors may not notice it started |
| A button wired to an audio element | Plays the stream right where the visitor is | Your own theme, a sticky header bar | Stops when the visitor follows a link to another page |
| The embeddable player | Plays in the station's own player inside your page | Home page, a dedicated listen page | Needs a space in the layout that fits it |
Many stations combine them: the embedded player on the home page, and a small Listen live link in the header of every other page that opens the pop-out player.
What to have ready
- The HTTPS listen link. Each station on our SSL radio streaming plans has one in the control panel, alongside an http version kept for legacy players. Your website takes the HTTPS version.
- A site served over HTTPS. A secure page will not load an insecure stream it cannot upgrade. If your site still runs on plain http, move it to HTTPS first; our web hosting with a control panel issues and renews certificates for you.
- An address people can say on air. A short domain name for the site makes "tap Listen live at" easy to read out between songs.
- Your station name and artwork, for the button label and the phone lock screen.
Never put a stream address that uses a raw IP address into an https page. Browsers upgrade http audio requests to https automatically, but they block the request outright when the host is an IP address instead of a domain name.
The button, in code
Paste this where the button should appear and replace the placeholder address with your HTTPS listen link. It uses only standard browser features: an audio element with no visible controls, and a real button element that starts and stops it.
<button type="button" id="listen">Listen live</button>
<audio id="radio" preload="none"
src="https://your-station.example/stream"></audio>
<script>
const btn = document.getElementById('listen');
const radio = document.getElementById('radio');
btn.addEventListener('click', () => {
if (radio.paused) {
btn.textContent = 'Connecting';
radio.play().catch((err) => {
if (err.name === 'AbortError') return;
btn.textContent = 'Listen live';
window.open(radio.src, '_blank', 'noopener');
});
} else {
radio.pause();
radio.load();
btn.textContent = 'Listen live';
}
});
radio.addEventListener('playing', () => { btn.textContent = 'Stop'; });
radio.addEventListener('waiting', () => { btn.textContent = 'Buffering'; });
</script>
What each part does:
preload="none"keeps the browser from opening the stream until the tap, so a visitor who never listens uses no data and does not show up as a listener.play()returns a promise. If the browser refuses to start the audio, thecatchopens the stream in a new tab instead of leaving a dead button; it ignores the AbortError raised when the visitor taps Stop before sound starts.- On stop,
pause()followed byload()drops the connection. The next tap fetches the stream fresh, so the listener rejoins the live broadcast rather than an old buffer. - The
playingandwaitingevents keep the label honest: it says Stop only once sound is actually coming out.
To confirm it worked, tap the button on your own site, wait for audio, and check that the label reads Stop. Then open your station's statistics: the current listener count should go up by one.
Where it goes on the page
- In the header of every page, to the right of the menu. Listeners arrive on any page from search, social posts and show notes, not only the home page.
- At the top of the home page, large, next to what is on now. The embedded player does this job if you use it.
- On each show page, next to the show times, so a fan of one programme can start it straight away.
- In a sticky bar on phones, pinned to the bottom of the screen, where a thumb reaches it.
Size matters on touch screens. The accessibility guidelines ask for pointer targets of at least 24 by 24 CSS pixels, and recommend 44 by 44 for the higher level. Give the button a visible label that says what it does; Listen live beats a bare play icon for someone using a screen reader.
Use a button element for a control that plays audio on the page, and an a element for one that goes somewhere, such as the pop-out player. Screen reader users expect a link to take them to a new place and a button to act on the current one.
How it behaves on phones
- Nothing plays without a tap. Browsers generally block audible playback that a script starts before the visitor has clicked or tapped anything on the page. Never set the stream to autoplay; make the button the start.
- Leaving the page ends the audio. On a normal multi-page site, following any link unloads the audio element. Send phone visitors to the pop-out player in its own tab if you want listening to survive browsing.
- The lock screen can show your station. The browser's Media Session feature lets the page hand the phone a title, artist and artwork, and react to the play and pause keys on headphones and the lock screen. Set it after playback has started.
- Data counts. The station's embeddable player offers a mobile data saver, and a Platinum station carries 3 streams, letting phones pick a lower bitrate.
Check it on a real phone, on mobile data rather than office Wi-Fi: tap, lock the screen, and confirm the audio keeps going and your station name shows on the lock screen.
Checks before you announce it
- Open your site in Chrome, Safari, Firefox and Edge. Tap the button in each; audio should start within a few seconds.
- Keep the developer tools console open while you tap. There should be no mixed content warning and no failed request for the stream.
- Tap stop, wait a minute, tap again. You should hear what is on air now, not what was playing a minute ago.
- Try it with your encoder disconnected. On the free plan the button should fail cleanly; on paid plans AutoDJ or your fallback list should keep sound on the link.
- Check your live listener count rises when you tap and falls when you stop.
When it goes wrong
| Symptom | Likely cause | What to do |
|---|---|---|
| Button does nothing, console shows a blocked request | The stream address uses http with an IP host | Swap in the HTTPS listen link with its domain name |
| Works on desktop, silent on the phone | Playback was started by a script, not by the tap | Call play() directly inside the click handler |
| Spins for ever, then stops | The station is off air or the link is mistyped | Open the listen link alone in a tab; if it fails there, check the encoder |
| Audio stops when visitors browse | The page with the audio element was unloaded | Link to the pop-out player in a new tab instead |
| Old audio after resuming | The element resumed from its buffer | Call load() after pause(), as in the example |
If the listen link itself will not play in a bare browser tab, the problem is upstream of your website. Check the encoder's connection settings in your control panel, then open a ticket or a chat: live chat runs 24/7.