Try HTTPS upgrade for HTTP streams, show error on failure
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:
parent
38451514c2
commit
83304c197d
1 changed files with 20 additions and 1 deletions
|
|
@ -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 = '▶ 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';
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue