@@ -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 ) ,
@@ -439,6 +440,9 @@ impl Spirc {
439440 pub fn set_position_ms ( & self , position_ms : u32 ) -> Result < ( ) , Error > {
440441 Ok ( self . commands . send ( SpircCommand :: SetPosition ( position_ms) ) ?)
441442 }
443+ pub fn seek_offset ( & self , offset_ms : i32 ) -> Result < ( ) , Error > {
444+ Ok ( self . commands . send ( SpircCommand :: SeekOffset ( offset_ms) ) ?)
445+ }
442446 pub fn disconnect ( & self ) -> Result < ( ) , Error > {
443447 Ok ( self . commands . send ( SpircCommand :: Disconnect ) ?)
444448 }
@@ -656,6 +660,10 @@ impl SpircTask {
656660 self . handle_seek ( position) ;
657661 self . notify ( None )
658662 }
663+ SpircCommand :: SeekOffset ( offset) => {
664+ self . handle_seek_offset ( offset) ;
665+ self . notify ( None )
666+ }
659667 SpircCommand :: SetVolume ( volume) => {
660668 self . set_volume ( volume) ;
661669 self . notify ( None )
@@ -1172,6 +1180,25 @@ impl SpircTask {
11721180 } ;
11731181 }
11741182
1183+ fn handle_seek_offset ( & mut self , offset_ms : i32 ) {
1184+ let position_ms = match self . play_status {
1185+ SpircPlayStatus :: Stopped => return ,
1186+ SpircPlayStatus :: LoadingPause { position_ms }
1187+ | SpircPlayStatus :: LoadingPlay { position_ms }
1188+ | SpircPlayStatus :: Paused { position_ms, .. } => position_ms,
1189+ SpircPlayStatus :: Playing {
1190+ nominal_start_time, ..
1191+ } => {
1192+ let now = self . now_ms ( ) ;
1193+ ( now - nominal_start_time) as u32
1194+ }
1195+ } ;
1196+
1197+ let position_ms = ( ( position_ms as i32 ) + offset_ms) . max ( 0 ) as u32 ;
1198+
1199+ self . handle_seek ( position_ms) ;
1200+ }
1201+
11751202 fn consume_queued_track ( & mut self ) -> usize {
11761203 // Removes current track if it is queued
11771204 // Returns the index of the next track
0 commit comments