diff --git a/radio/urls.py b/radio/urls.py index 65ecb01..acd6c77 100644 --- a/radio/urls.py +++ b/radio/urls.py @@ -18,4 +18,5 @@ urlpatterns = [ path('radio/notes//', views.save_station_notes, name='save_station_notes'), path('radio/focus/record/', views.record_focus_session, name='record_focus_session'), path('radio/focus/stats/', views.focus_stats, name='focus_stats'), + path('radio/stream-player/', views.stream_player, name='stream_player'), ] diff --git a/radio/views.py b/radio/views.py index 29a29df..af6a122 100644 --- a/radio/views.py +++ b/radio/views.py @@ -1,4 +1,6 @@ import json +import socket +import ssl as ssl_module import time import urllib.parse from datetime import datetime @@ -573,3 +575,18 @@ def import_m3u(request): skipped += 1 return JsonResponse({'ok': True, 'added': added, 'skipped': skipped}) + + +# --------------------------------------------------------------------------- +# Minimal HTTP stream player (standalone tab for mixed-content streams) +# --------------------------------------------------------------------------- + +def stream_player(request): + url = request.GET.get('url', '').strip() + name = request.GET.get('name', '').strip() + vol = request.GET.get('vol', '204').strip() + try: + vol = max(0, min(255, int(vol))) + except ValueError: + vol = 204 + return render(request, 'radio/stream_player.html', {'stream_url': url, 'stream_name': name, 'stream_vol': vol}) diff --git a/static/js/app.js b/static/js/app.js index c91f6e4..f008577 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -67,28 +67,18 @@ function escapeHtml(str) { function playStation(url, name, stationId) { stopPlayback(false); + // HTTP stream on HTTPS page → open minimal player in new tab, keep main window as home base + if (location.protocol === 'https:' && url.startsWith('http://')) { + const vol = localStorage.getItem('diora_volume') || '204'; + const params = new URLSearchParams({ url, name, vol }); + window.open('/radio/stream-player/?' + params, '_blank'); + return; + } + currentStation = { url, name, id: stationId || null }; isPlaying = true; - // 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; + audio.src = url; const volSlider = document.getElementById('volume'); if (volSlider) audio.volume = volSlider.value / 255; audio.play().catch(() => { diff --git a/templates/radio/stream_player.html b/templates/radio/stream_player.html new file mode 100644 index 0000000..6b270d1 --- /dev/null +++ b/templates/radio/stream_player.html @@ -0,0 +1,157 @@ + + + + + + {{ stream_name|default:"Radio" }} + + + +
{{ stream_name|default:"Radio" }}
+
+ +
+ +
+ vol + + +
+
+ + + + + +