Try HTTPS upgrade for HTTP streams, show error on failure
All checks were successful
Build and push Docker image / build (push) Successful in 14s
Test / test (push) Successful in 16s

Browsers block HTTP (mixed content) audio from HTTPS pages. On playStation,
if the URL is http:// and page is https://, try the https:// version first.
If the stream fails to load, show a clear error in the track display instead
of silently doing nothing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
marwin 2026-03-21 17:22:51 +01:00
parent 38451514c2
commit 83304c197d

View file

@ -70,7 +70,25 @@ function playStation(url, name, stationId) {
currentStation = { url, name, id: stationId || null }; currentStation = { url, name, id: stationId || null };
isPlaying = true; isPlaying = true;
audio.src = url; // If page is HTTPS and stream is HTTP, try upgrading to HTTPS first.
// Browsers block mixed content (HTTP media on HTTPS pages).
const playUrl = (location.protocol === 'https:' && url.startsWith('http://'))
? url.replace('http://', 'https://')
: url;
audio.onerror = () => {
const wasUpgraded = playUrl !== url;
if (wasUpgraded) {
$('now-playing-track').textContent = 'Stream nicht erreichbar (HTTP-only, kein HTTPS-Fallback)';
} else {
$('now-playing-track').textContent = 'Stream konnte nicht geladen werden';
}
isPlaying = false;
$('play-stop-btn').textContent = '&#9654; Play';
$('play-stop-btn').classList.remove('playing');
};
audio.src = playUrl;
const volSlider = document.getElementById('volume'); const volSlider = document.getElementById('volume');
if (volSlider) audio.volume = volSlider.value / 255; if (volSlider) audio.volume = volSlider.value / 255;
audio.play().catch(() => { audio.play().catch(() => {
@ -113,6 +131,7 @@ function stopPlayback(clearStation = true) {
audio.src = ''; audio.src = '';
audio.ontimeupdate = null; audio.ontimeupdate = null;
audio.onended = null; audio.onended = null;
audio.onerror = null;
isPlaying = false; isPlaying = false;
podcastMode = false; podcastMode = false;
if ('mediaSession' in navigator) navigator.mediaSession.playbackState = 'none'; if ('mediaSession' in navigator) navigator.mediaSession.playbackState = 'none';