diff --git a/README.md b/README.md
index 49a4a10..130d62b 100644
--- a/README.md
+++ b/README.md
@@ -36,7 +36,9 @@ The current host uses the NVIDIA Compose override for Tunarr's CUDA transcode pr
Tune to channel 99 in the retroLabs Roku app. This host is configured for Dunnellon, FL (34431). The screen rotates through current conditions, six hourly periods, six extended forecast periods, and sunrise/sunset. Active NWS alerts appear across the rotation. The bridge caches data and marks delayed responses.
-To set a location on another host, set `RETROTV_WEATHER_POINT` (latitude,longitude) and `RETROTV_WEATHER_LOCATION` in `.env`, then run `docker compose up -d --no-deps bridge`. The bridge serves the feed at `/api/v1/weather`. Weather is rendered by the Roku app.
+To set a location on another host, set `RETROTV_WEATHER_POINT` (latitude,longitude) and `RETROTV_WEATHER_LOCATION` in `.env`, then run `docker compose up -d --no-deps bridge`. The bridge serves the feed at `/api/v1/weather`. Weather is rendered by the Roku app. Its muted live inset shows the last tuned linear channel, or the first linear channel when weather is opened directly. The inset shares the tuner's video player.
+
+To add background music, place a local MP3 at `data/weather/forecast.mp3` on the bridge host. The file is served over the LAN and loops while the weather channel is open. The directory is mounted read-only in the bridge and ignored by Git.
## Roku
diff --git a/bridge/app.py b/bridge/app.py
index f5ecb28..9b921d2 100644
--- a/bridge/app.py
+++ b/bridge/app.py
@@ -10,7 +10,7 @@ from xml.etree import ElementTree as XML
import httpx
from fastapi import FastAPI, HTTPException, Query, Request
-from fastapi.responses import RedirectResponse, Response, StreamingResponse
+from fastapi.responses import FileResponse, RedirectResponse, Response, StreamingResponse
from starlette.background import BackgroundTask
from .discovery import SERVICE, start_discovery
@@ -115,6 +115,7 @@ def create_app(*, tunarr_url=None, transport=None, discover=True, id_file=None):
base_url = f"http://{ip}:{port}"
name = os.getenv("RETROTV_NAME", "retroLabs")
weather_provider = NWSWeather()
+ weather_music = Path(os.getenv("RETROTV_WEATHER_MUSIC", "data/weather/forecast.mp3"))
upstream = tunarr_url or os.getenv("RETROTV_TUNARR_URL", "http://127.0.0.1:14242")
identity = Path(id_file or os.getenv("RETROTV_ID_FILE", "data/server-id"))
@@ -222,7 +223,14 @@ def create_app(*, tunarr_url=None, transport=None, discover=True, id_file=None):
@app.get("/api/v1/weather")
async def weather():
- return await weather_provider.read()
+ data = await weather_provider.read()
+ return {**data, "musicUrl": "/api/v1/weather/music.mp3" if weather_music.is_file() else None}
+
+ @app.get("/api/v1/weather/music.mp3")
+ async def weather_audio():
+ if not weather_music.is_file():
+ raise HTTPException(404, "Weather music is not configured")
+ return FileResponse(weather_music, media_type="audio/mpeg")
async def proxy(request, path, *, playlist=False, params=None):
client = app.state.tunarr
diff --git a/compose.yaml b/compose.yaml
index 55b7123..8c74f49 100644
--- a/compose.yaml
+++ b/compose.yaml
@@ -37,6 +37,7 @@ services:
RETROTV_WEATHER_LOCATION: ${RETROTV_WEATHER_LOCATION:-Local Weather}
volumes:
- bridge-data:/state
+ - ./data/weather:/app/data/weather:ro
volumes:
tunarr-data:
diff --git a/roku/components/Guide.brs b/roku/components/Guide.brs
index cf449c4..2001c51 100644
--- a/roku/components/Guide.brs
+++ b/roku/components/Guide.brs
@@ -46,6 +46,10 @@ sub onMenuSelect(event as object)
openGuide()
else if index = 1
m.channelIndex = -1
+ m.weather.visible = false
+ stopWeather()
+ m.videoChannelId = invalid
+ m.video.visible = false
m.video.control = "stop"
m.retryTimer.control = "stop"
loadLineup()
diff --git a/roku/components/RetroScene.brs b/roku/components/RetroScene.brs
index 0f457f0..a9d1555 100644
--- a/roku/components/RetroScene.brs
+++ b/roku/components/RetroScene.brs
@@ -27,6 +27,7 @@ sub findServer(baseUrl as string, useSaved as boolean)
m.weather.visible = false
stopWeather()
m.video.control = "stop"
+ m.videoChannelId = invalid
m.video.visible = false
m.playbackStatus.visible = false
m.retryTimer.control = "stop"
@@ -154,16 +155,26 @@ end sub
sub startPlayback()
if m.channelIndex < 0 then return
channel = m.channels[m.channelIndex]
- m.video.control = "stop"
m.weather.visible = channel.type = "weather"
- m.video.visible = not m.weather.visible
m.playbackStatus.visible = false
if m.weather.visible
startWeather()
return
end if
stopWeather()
+ m.video.visible = true
+ m.video.translation = [0, 0]
+ m.video.width = 1280
+ m.video.height = 720
+ m.video.mute = false
+ if m.videoChannelId = channel.id and m.video.state = "playing" then return
+ setPlaybackStatus("Tuning…")
+ playLinear(channel)
+end sub
+sub playLinear(channel as object)
+ m.video.control = "stop"
+ m.videoChannelId = invalid
streamUrl = channel.streamUrl
if GetInterface(streamUrl, "ifString") = invalid or streamUrl = ""
setPlaybackStatus("This channel has no stream.")
@@ -176,7 +187,7 @@ sub startPlayback()
content.live = true
content.title = channel.name
m.video.content = content
- setPlaybackStatus("Tuning…")
+ m.videoChannelId = channel.id
m.video.control = "play"
end sub
@@ -278,7 +289,11 @@ sub setPlaybackStatus(message as string)
end sub
sub onVideoState()
- if m.channelIndex < 0 or m.weather.visible then return
+ if m.weather.visible
+ if m.video.state = "error" or m.video.state = "finished" then hideWeatherPreview()
+ return
+ end if
+ if m.channelIndex < 0 then return
if m.video.state = "playing"
m.playbackStatus.visible = false
m.retryCount = 0
@@ -324,7 +339,7 @@ function onKeyEvent(key as string, press as boolean) as boolean
if m.previousIndex >= 0 then tune(m.previousIndex)
return true
else if LCase(key) = "ok"
- if m.video.state = "error" or m.video.state = "finished"
+ if not m.weather.visible and (m.video.state = "error" or m.video.state = "finished")
tune(m.channelIndex)
else
showBanner()
diff --git a/roku/components/RetroScene.xml b/roku/components/RetroScene.xml
index 1cbe20b..c6f135f 100644
--- a/roku/components/RetroScene.xml
+++ b/roku/components/RetroScene.xml
@@ -4,7 +4,7 @@
-
+
@@ -14,13 +14,18 @@
font="font:MediumBoldSystemFont" color="0x78E5EBFF" />
-
+
+
+
+
diff --git a/roku/components/Weather.brs b/roku/components/Weather.brs
index 12e47f5..5a373ca 100644
--- a/roku/components/Weather.brs
+++ b/roku/components/Weather.brs
@@ -1,5 +1,5 @@
sub initWeather()
- for each id in ["weatherLocation", "weatherHeading", "weatherBody", "weatherAlerts", "weatherSource", "weatherRotation", "weatherRefresh"]
+ for each id in ["weatherLocation", "weatherHeading", "weatherBody", "weatherAlerts", "weatherSource", "weatherRotation", "weatherRefresh", "weatherAudio", "weatherPreviewFrame", "weatherPreviewLabel"]
m[id] = m.top.FindNode(id)
end for
m.weatherRotation.ObserveField("fire", "rotateWeather")
@@ -14,11 +14,51 @@ sub startWeather()
m.weatherBody.text = ""
m.weatherAlerts.text = ""
m.weatherSource.text = ""
+ startWeatherPreview()
refreshWeather()
m.weatherRefresh.control = "start"
end sub
+sub startWeatherPreview()
+ preview = invalid
+ if m.previousIndex >= 0 and m.previousIndex < m.channels.Count()
+ candidate = m.channels[m.previousIndex]
+ if candidate.type = "linear" then preview = candidate
+ end if
+ if preview = invalid
+ for each candidate in m.channels
+ if candidate.type = "linear"
+ preview = candidate
+ exit for
+ end if
+ end for
+ end if
+ if preview = invalid
+ hideWeatherPreview()
+ return
+ end if
+
+ m.video.translation = [804, 212]
+ m.video.width = 408
+ m.video.height = 230
+ m.video.mute = true
+ m.video.visible = true
+ m.weatherPreviewFrame.visible = true
+ m.weatherPreviewLabel.text = "LIVE " + channelLabel(preview)
+ if m.videoChannelId <> preview.id or m.video.state <> "playing" then playLinear(preview)
+end sub
+
+sub hideWeatherPreview()
+ m.video.visible = false
+ m.video.control = "stop"
+ m.videoChannelId = invalid
+ m.weatherPreviewFrame.visible = false
+ m.weatherPreviewLabel.text = ""
+end sub
+
sub stopWeather()
+ m.weatherAudio.control = "stop"
+ m.weatherMusicUrl = invalid
m.weatherRotation.control = "stop"
m.weatherRefresh.control = "stop"
if m.weatherWorker <> invalid
@@ -38,6 +78,7 @@ sub onWeather(event as object)
if not m.weather.visible then return
firstResult = m.weatherData = invalid
m.weatherData = event.GetData().data
+ if m.weatherData <> invalid then updateWeatherMusic(m.weatherData.musicUrl)
renderWeather()
if firstResult then m.weatherRotation.control = "start"
end sub
@@ -109,3 +150,15 @@ function tempLabel(value as dynamic) as string
if value = invalid then return "—"
return StrI(value).Trim() + "°F"
end function
+
+sub updateWeatherMusic(path as dynamic)
+ if path = m.weatherMusicUrl then return
+ m.weatherAudio.control = "stop"
+ m.weatherMusicUrl = path
+ if GetInterface(path, "ifString") = invalid or path = "" then return
+ track = CreateObject("roSGNode", "ContentNode")
+ track.url = m.server.baseUrl + path
+ track.streamFormat = "mp3"
+ m.weatherAudio.content = track
+ m.weatherAudio.control = "play"
+end sub