From 83c9bcf12ed7b094a86ae7cf55c5e70c493b94d1 Mon Sep 17 00:00:00 2001 From: Gregor Klevze Date: Wed, 14 Jan 2026 18:42:16 +0100 Subject: [PATCH] cast info --- sidecar/index.js | 24 ++++++++++++++---------- src-tauri/src/lib.rs | 13 ++++++++++++- src/main.js | 8 +++++++- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/sidecar/index.js b/sidecar/index.js index 82d6720..6150d73 100644 --- a/sidecar/index.js +++ b/sidecar/index.js @@ -58,7 +58,7 @@ rl.on('line', (line) => { switch (command) { case 'play': - play(args.ip, args.url); + play(args.ip, args.url, args.metadata); break; case 'stop': stop(); @@ -74,12 +74,13 @@ rl.on('line', (line) => { } }); -function play(ip, url) { +function play(ip, url, metadata) { if (activeClient) { try { activeClient.close(); } catch (e) { } } activeClient = new Client(); + activeClient._playMetadata = metadata || {}; activeClient.connect(ip, () => { log(`Connected to ${ip}`); @@ -106,10 +107,10 @@ function play(ip, url) { log('Join failed, attempting launch...'); log(`Join error: ${err && err.message ? err.message : String(err)}`); // Join can fail if the session is stale; stop it and retry launch. - stopSessions(activeClient, [session], () => launchPlayer(url, /*didStopFirst*/ true)); + stopSessions(activeClient, [session], () => launchPlayer(url, activeClient._playMetadata, /*didStopFirst*/ true)); } else { activePlayer = player; - loadMedia(url); + loadMedia(url, activeClient._playMetadata); } }); } else { @@ -117,7 +118,7 @@ function play(ip, url) { if (sessions.length > 0) { log('Non-media session detected; skipping stop and launching DefaultMediaReceiver...'); } - launchPlayer(url, /*didStopFirst*/ false); + launchPlayer(url, activeClient._playMetadata, /*didStopFirst*/ false); } }); }); @@ -130,7 +131,7 @@ function play(ip, url) { }); } -function launchPlayer(url, didStopFirst) { +function launchPlayer(url, metadata, didStopFirst) { if (!activeClient) return; activeClient.launch(DefaultMediaReceiver, (err, player) => { @@ -154,7 +155,7 @@ function launchPlayer(url, didStopFirst) { return; } activePlayer = retryPlayer; - loadMedia(url); + loadMedia(url, metadata); }); }); }); @@ -166,20 +167,23 @@ function launchPlayer(url, didStopFirst) { return; } activePlayer = player; - loadMedia(url); + loadMedia(url, metadata); }); } -function loadMedia(url) { +function loadMedia(url, metadata) { if (!activePlayer) return; + const meta = metadata || {}; const media = { contentId: url, contentType: 'audio/mpeg', streamType: 'LIVE', metadata: { metadataType: 0, - title: 'RadioPlayer' + title: meta.title || 'RadioPlayer', + subtitle: meta.artist || meta.station || undefined, + images: meta.image ? [{ url: meta.image }] : undefined } }; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 78479bc..6fa1d3d 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -374,6 +374,9 @@ async fn cast_play( sidecar_state: State<'_, SidecarState>, device_name: String, url: String, + title: Option, + artist: Option, + image: Option, ) -> Result<(), String> { // Resolve device name -> ip with diagnostics on failure let ip = { @@ -436,7 +439,15 @@ async fn cast_play( let play_cmd = json!({ "command": "play", - "args": { "ip": ip, "url": url } + "args": { + "ip": ip, + "url": url, + "metadata": { + "title": title, + "artist": artist, + "image": image + } + } }); let play_payload = format!("{}\n", play_cmd.to_string()); info!("Sending cast URL to device '{}': {}", device_name, url); diff --git a/src/main.js b/src/main.js index a12e6e7..71ec7f2 100644 --- a/src/main.js +++ b/src/main.js @@ -1263,7 +1263,13 @@ async function play() { currentCastTransport = 'direct'; } - await invoke('cast_play', { deviceName: currentCastDevice, url: castUrl }); + await invoke('cast_play', { + deviceName: currentCastDevice, + url: castUrl, + title: station.title || 'Radio', + artist: station.slogan || undefined, + image: station.logo || undefined + }); isPlaying = true; // Sync volume const vol = volumeSlider.value / 100;