cast info
This commit is contained in:
@@ -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
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -374,6 +374,9 @@ async fn cast_play(
|
||||
sidecar_state: State<'_, SidecarState>,
|
||||
device_name: String,
|
||||
url: String,
|
||||
title: Option<String>,
|
||||
artist: Option<String>,
|
||||
image: Option<String>,
|
||||
) -> 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user