@@ -121,6 +121,7 @@ pub enum SpircCommand {
121121 Repeat ( bool ) ,
122122 Disconnect ,
123123 SetPosition ( u32 ) ,
124+ SeekOffset ( i32 ) ,
124125 SetVolume ( u16 ) ,
125126 Activate ,
126127 Load ( SpircLoadCommand ) ,
@@ -436,6 +437,9 @@ impl Spirc {
436437 pub fn set_position_ms ( & self , position_ms : u32 ) -> Result < ( ) , Error > {
437438 Ok ( self . commands . send ( SpircCommand :: SetPosition ( position_ms) ) ?)
438439 }
440+ pub fn seek_offset ( & self , offset_ms : i32 ) -> Result < ( ) , Error > {
441+ Ok ( self . commands . send ( SpircCommand :: SeekOffset ( offset_ms) ) ?)
442+ }
439443 pub fn disconnect ( & self ) -> Result < ( ) , Error > {
440444 Ok ( self . commands . send ( SpircCommand :: Disconnect ) ?)
441445 }
@@ -638,6 +642,10 @@ impl SpircTask {
638642 self . handle_seek ( position) ;
639643 self . notify ( None )
640644 }
645+ SpircCommand :: SeekOffset ( offset) => {
646+ self . handle_seek_offset ( offset) ;
647+ self . notify ( None )
648+ }
641649 SpircCommand :: SetVolume ( volume) => {
642650 self . set_volume ( volume) ;
643651 self . notify ( None )
@@ -1154,6 +1162,25 @@ impl SpircTask {
11541162 } ;
11551163 }
11561164
1165+ fn handle_seek_offset ( & mut self , offset_ms : i32 ) {
1166+ let position_ms = match self . play_status {
1167+ SpircPlayStatus :: Stopped => return ,
1168+ SpircPlayStatus :: LoadingPause { position_ms }
1169+ | SpircPlayStatus :: LoadingPlay { position_ms }
1170+ | SpircPlayStatus :: Paused { position_ms, .. } => position_ms,
1171+ SpircPlayStatus :: Playing {
1172+ nominal_start_time, ..
1173+ } => {
1174+ let now = self . now_ms ( ) ;
1175+ ( now - nominal_start_time) as u32
1176+ }
1177+ } ;
1178+
1179+ let position_ms = ( ( position_ms as i32 ) + offset_ms) . max ( 0 ) as u32 ;
1180+
1181+ self . handle_seek ( position_ms) ;
1182+ }
1183+
11571184 fn consume_queued_track ( & mut self ) -> usize {
11581185 // Removes current track if it is queued
11591186 // Returns the index of the next track
0 commit comments