@@ -126,6 +126,7 @@ enum SpircCommand {
126126 RepeatTrack ( bool ) ,
127127 Disconnect { pause : bool } ,
128128 SetPosition ( u32 ) ,
129+ SeekOffset ( i32 ) ,
129130 SetVolume ( u16 ) ,
130131 Activate ,
131132 Load ( LoadRequest ) ,
@@ -385,6 +386,13 @@ impl Spirc {
385386 Ok ( self . commands . send ( SpircCommand :: Load ( command) ) ?)
386387 }
387388
389+ /// Seek to given offset.
390+ ///
391+ /// Does nothing if we are not the active device.
392+ pub fn seek_offset ( & self , offset_ms : i32 ) -> Result < ( ) , Error > {
393+ Ok ( self . commands . send ( SpircCommand :: SeekOffset ( offset_ms) ) ?)
394+ }
395+
388396 /// Disconnects the current device and pauses the playback according the value.
389397 ///
390398 /// Does nothing if we are not the active device.
@@ -651,6 +659,7 @@ impl SpircTask {
651659 SpircCommand :: Repeat ( repeat) => self . handle_repeat_context ( repeat) ?,
652660 SpircCommand :: RepeatTrack ( repeat) => self . handle_repeat_track ( repeat) ,
653661 SpircCommand :: SetPosition ( position) => self . handle_seek ( position) ,
662+ SpircCommand :: SeekOffset ( offset) => self . handle_seek_offset ( offset) ,
654663 SpircCommand :: SetVolume ( volume) => self . set_volume ( volume) ,
655664 SpircCommand :: Load ( command) => self . handle_load ( command, None ) . await ?,
656665 } ;
@@ -1461,6 +1470,25 @@ impl SpircTask {
14611470 } ;
14621471 }
14631472
1473+ fn handle_seek_offset ( & mut self , offset_ms : i32 ) {
1474+ let position_ms = match self . play_status {
1475+ SpircPlayStatus :: Stopped => return ,
1476+ SpircPlayStatus :: LoadingPause { position_ms }
1477+ | SpircPlayStatus :: LoadingPlay { position_ms }
1478+ | SpircPlayStatus :: Paused { position_ms, .. } => position_ms,
1479+ SpircPlayStatus :: Playing {
1480+ nominal_start_time, ..
1481+ } => {
1482+ let now = self . now_ms ( ) ;
1483+ ( now - nominal_start_time) as u32
1484+ }
1485+ } ;
1486+
1487+ let position_ms = ( ( position_ms as i32 ) + offset_ms) . max ( 0 ) as u32 ;
1488+
1489+ self . handle_seek ( position_ms) ;
1490+ }
1491+
14641492 fn handle_shuffle ( & mut self , shuffle : bool ) -> Result < ( ) , Error > {
14651493 self . player . emit_shuffle_changed_event ( shuffle) ;
14661494 self . connect_state . handle_shuffle ( shuffle)
0 commit comments