diff --git a/static/js/app.js b/static/js/app.js index 7b27abe..c91f6e4 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -70,7 +70,25 @@ function playStation(url, name, stationId) { currentStation = { url, name, id: stationId || null }; 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 = '▶ Play'; + $('play-stop-btn').classList.remove('playing'); + }; + + audio.src = playUrl; const volSlider = document.getElementById('volume'); if (volSlider) audio.volume = volSlider.value / 255; audio.play().catch(() => { @@ -113,6 +131,7 @@ function stopPlayback(clearStation = true) { audio.src = ''; audio.ontimeupdate = null; audio.onended = null; + audio.onerror = null; isPlaying = false; podcastMode = false; if ('mediaSession' in navigator) navigator.mediaSession.playbackState = 'none';