File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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} ;
1717use 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 ( ) {
You can’t perform that action at this time.
0 commit comments