Skip to content

Commit da88fbb

Browse files
committed
Skip failed downloads and print error instead of hanging
1 parent d0ed33f commit da88fbb

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/download.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use librespot::{
1111
audio_backend,
1212
config::{AudioFormat, Bitrate, PlayerConfig},
1313
mixer::NoOpVolume,
14-
player::Player,
14+
player::{Player, PlayerEvent},
1515
},
1616
};
1717
use once_cell::sync::{Lazy, OnceCell};
@@ -235,9 +235,24 @@ impl Loader {
235235
move || backend(Some("temp.pcm".into()), AudioFormat::S16),
236236
);
237237

238+
let mut rx = player.get_player_event_channel();
239+
238240
player.load(track_ref, true, 0);
239241

242+
let player_ref = player.clone();
243+
244+
let task = tokio::spawn(async move {
245+
while let Some(event) = rx.recv().await {
246+
if let PlayerEvent::Unavailable { .. } = event {
247+
log::error!("Player is unavailable");
248+
player_ref.stop();
249+
break;
250+
}
251+
}
252+
});
253+
240254
player.await_end_of_track().await;
255+
task.abort();
241256

242257
// Read track as stereo signed 16-bit PCM and encode into audio file
243258
let mut cmd = if args.format == OutputFormat::Wav || input_format.is_none() {

0 commit comments

Comments
 (0)