cast info
This commit is contained in:
@@ -58,7 +58,7 @@ rl.on('line', (line) => {
|
|||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case 'play':
|
case 'play':
|
||||||
play(args.ip, args.url);
|
play(args.ip, args.url, args.metadata);
|
||||||
break;
|
break;
|
||||||
case 'stop':
|
case 'stop':
|
||||||
stop();
|
stop();
|
||||||
@@ -74,12 +74,13 @@ rl.on('line', (line) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function play(ip, url) {
|
function play(ip, url, metadata) {
|
||||||
if (activeClient) {
|
if (activeClient) {
|
||||||
try { activeClient.close(); } catch (e) { }
|
try { activeClient.close(); } catch (e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
activeClient = new Client();
|
activeClient = new Client();
|
||||||
|
activeClient._playMetadata = metadata || {};
|
||||||
|
|
||||||
activeClient.connect(ip, () => {
|
activeClient.connect(ip, () => {
|
||||||
log(`Connected to ${ip}`);
|
log(`Connected to ${ip}`);
|
||||||
@@ -106,10 +107,10 @@ function play(ip, url) {
|
|||||||
log('Join failed, attempting launch...');
|
log('Join failed, attempting launch...');
|
||||||
log(`Join error: ${err && err.message ? err.message : String(err)}`);
|
log(`Join error: ${err && err.message ? err.message : String(err)}`);
|
||||||
// Join can fail if the session is stale; stop it and retry launch.
|
// 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 {
|
} else {
|
||||||
activePlayer = player;
|
activePlayer = player;
|
||||||
loadMedia(url);
|
loadMedia(url, activeClient._playMetadata);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -117,7 +118,7 @@ function play(ip, url) {
|
|||||||
if (sessions.length > 0) {
|
if (sessions.length > 0) {
|
||||||
log('Non-media session detected; skipping stop and launching DefaultMediaReceiver...');
|
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;
|
if (!activeClient) return;
|
||||||
|
|
||||||
activeClient.launch(DefaultMediaReceiver, (err, player) => {
|
activeClient.launch(DefaultMediaReceiver, (err, player) => {
|
||||||
@@ -154,7 +155,7 @@ function launchPlayer(url, didStopFirst) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
activePlayer = retryPlayer;
|
activePlayer = retryPlayer;
|
||||||
loadMedia(url);
|
loadMedia(url, metadata);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -166,20 +167,23 @@ function launchPlayer(url, didStopFirst) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
activePlayer = player;
|
activePlayer = player;
|
||||||
loadMedia(url);
|
loadMedia(url, metadata);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadMedia(url) {
|
function loadMedia(url, metadata) {
|
||||||
if (!activePlayer) return;
|
if (!activePlayer) return;
|
||||||
|
|
||||||
|
const meta = metadata || {};
|
||||||
const media = {
|
const media = {
|
||||||
contentId: url,
|
contentId: url,
|
||||||
contentType: 'audio/mpeg',
|
contentType: 'audio/mpeg',
|
||||||
streamType: 'LIVE',
|
streamType: 'LIVE',
|
||||||
metadata: {
|
metadata: {
|
||||||
metadataType: 0,
|
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>,
|
sidecar_state: State<'_, SidecarState>,
|
||||||
device_name: String,
|
device_name: String,
|
||||||
url: String,
|
url: String,
|
||||||
|
title: Option<String>,
|
||||||
|
artist: Option<String>,
|
||||||
|
image: Option<String>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
// Resolve device name -> ip with diagnostics on failure
|
// Resolve device name -> ip with diagnostics on failure
|
||||||
let ip = {
|
let ip = {
|
||||||
@@ -436,7 +439,15 @@ async fn cast_play(
|
|||||||
|
|
||||||
let play_cmd = json!({
|
let play_cmd = json!({
|
||||||
"command": "play",
|
"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());
|
let play_payload = format!("{}\n", play_cmd.to_string());
|
||||||
info!("Sending cast URL to device '{}': {}", device_name, url);
|
info!("Sending cast URL to device '{}': {}", device_name, url);
|
||||||
|
|||||||
@@ -1263,7 +1263,13 @@ async function play() {
|
|||||||
currentCastTransport = 'direct';
|
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;
|
isPlaying = true;
|
||||||
// Sync volume
|
// Sync volume
|
||||||
const vol = volumeSlider.value / 100;
|
const vol = volumeSlider.value / 100;
|
||||||
|
|||||||
Reference in New Issue
Block a user