@@ -651,7 +651,7 @@ impl SpircTask {
651651 SpircCommand :: RepeatTrack ( repeat) => self . handle_repeat_track ( repeat) ,
652652 SpircCommand :: SetPosition ( position) => self . handle_seek ( position) ,
653653 SpircCommand :: SetVolume ( volume) => self . set_volume ( volume) ,
654- SpircCommand :: Load ( command) => self . handle_load ( command, None ) . await ?,
654+ SpircCommand :: Load ( command) => self . handle_load ( command, None , None ) . await ?,
655655 } ;
656656
657657 self . notify ( ) . await
@@ -998,6 +998,13 @@ impl SpircTask {
998998 . map ( Into :: into)
999999 . map ( LoadContextOptions :: Options ) ;
10001000
1001+ let fallback_index = play
1002+ . options
1003+ . skip_to
1004+ . as_ref ( )
1005+ . and_then ( |s| s. track_index )
1006+ . map ( |i| i as usize ) ;
1007+
10011008 self . handle_load (
10021009 LoadRequest {
10031010 context,
@@ -1009,6 +1016,7 @@ impl SpircTask {
10091016 } ,
10101017 } ,
10111018 play. context . pages . pop ( ) ,
1019+ fallback_index,
10121020 )
10131021 . await ?;
10141022
@@ -1217,6 +1225,7 @@ impl SpircTask {
12171225 & mut self ,
12181226 cmd : LoadRequest ,
12191227 page : Option < ContextPage > ,
1228+ fallback_index : Option < usize > ,
12201229 ) -> Result < ( ) , Error > {
12211230 self . connect_state
12221231 . reset_context ( if let PlayContext :: Uri ( ref uri) = cmd. context {
@@ -1253,17 +1262,26 @@ impl SpircTask {
12531262 let index = match cmd_options. playing_track {
12541263 None => None ,
12551264 Some ( ref playing_track) => Some ( match playing_track {
1256- PlayingTrack :: Index ( i) => * i as usize ,
1265+ PlayingTrack :: Index ( i) => Ok ( * i as usize ) ,
12571266 PlayingTrack :: Uri ( uri) => {
12581267 let ctx = self . connect_state . get_context ( ContextType :: Default ) ?;
1259- ConnectState :: find_index_in_context ( ctx, |t| & t. uri == uri) ?
1268+ ConnectState :: find_index_in_context ( ctx, |t| & t. uri == uri)
12601269 }
12611270 PlayingTrack :: Uid ( uid) => {
12621271 let ctx = self . connect_state . get_context ( ContextType :: Default ) ?;
1263- ConnectState :: find_index_in_context ( ctx, |t| & t. uid == uid) ?
1272+ ConnectState :: find_index_in_context ( ctx, |t| & t. uid == uid)
12641273 }
12651274 } ) ,
1266- } ;
1275+ }
1276+ . map ( |i| {
1277+ i. unwrap_or_else ( |why| {
1278+ warn ! (
1279+ "Failed to resolve index by {:?}, using fallback index: {:?} (Error: {why})" ,
1280+ cmd_options. playing_track, fallback_index
1281+ ) ;
1282+ fallback_index. unwrap_or_default ( )
1283+ } )
1284+ } ) ;
12671285
12681286 if let Some ( LoadContextOptions :: Options ( ref options) ) = cmd_options. context_options {
12691287 debug ! (
0 commit comments