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
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user