@@ -621,11 +621,17 @@ impl MprisPlayerService {
621
621
// Calling Play after this should cause playback to start again from the same position.
622
622
//
623
623
// If `self.can_pause` is `false`, attempting to call this method should have no effect.
624
- async fn pause ( & self ) {
624
+ async fn pause ( & self ) -> zbus :: fdo :: Result < ( ) > {
625
625
debug ! ( "org.mpris.MediaPlayer2.Player::Pause" ) ;
626
626
// FIXME: This should return an error if can_pause is false
627
- if let Some ( spirc) = & self . spirc {
628
- let _ = spirc. pause ( ) ;
627
+ match ( & self . spirc , & self . metadata . mpris . track_id ) {
628
+ ( Some ( spirc) , Some ( _) ) => spirc
629
+ . pause ( )
630
+ . map_err ( |err| zbus:: fdo:: Error :: Failed ( format ! ( "{err}" ) ) ) ,
631
+ ( Some ( _) , None ) => {
632
+ zbus:: fdo:: Result :: Err ( zbus:: fdo:: Error :: Failed ( String :: from ( "No track" ) ) )
633
+ }
634
+ _ => zbus:: fdo:: Result :: Err ( zbus:: fdo:: Error :: Failed ( String :: from ( "Can't play/pause" ) ) ) ,
629
635
}
630
636
}
631
637
@@ -637,11 +643,16 @@ impl MprisPlayerService {
637
643
//
638
644
// If `self.can_pause` is `false`, attempting to call this method should have no effect and
639
645
// raise an error.
640
- async fn play_pause ( & self ) {
646
+ async fn play_pause ( & self ) -> zbus :: fdo :: Result < ( ) > {
641
647
debug ! ( "org.mpris.MediaPlayer2.Player::PlayPause" ) ;
642
- // FIXME: This should return an error if can_pause is false
643
- if let Some ( spirc) = & self . spirc {
644
- let _ = spirc. play_pause ( ) ;
648
+ match ( & self . spirc , & self . metadata . mpris . track_id ) {
649
+ ( Some ( spirc) , Some ( _) ) => spirc
650
+ . play_pause ( )
651
+ . map_err ( |err| zbus:: fdo:: Error :: Failed ( format ! ( "{err}" ) ) ) ,
652
+ ( Some ( _) , None ) => {
653
+ zbus:: fdo:: Result :: Err ( zbus:: fdo:: Error :: Failed ( String :: from ( "No track" ) ) )
654
+ }
655
+ _ => zbus:: fdo:: Result :: Err ( zbus:: fdo:: Error :: Failed ( String :: from ( "Can't play/pause" ) ) ) ,
645
656
}
646
657
}
647
658
@@ -656,7 +667,6 @@ impl MprisPlayerService {
656
667
// an error.
657
668
async fn stop ( & self ) {
658
669
debug ! ( "org.mpris.MediaPlayer2.Player::Stop" ) ;
659
- // FIXME: This should return an error if can_control is false
660
670
if let Some ( spirc) = & self . spirc {
661
671
let _ = spirc. pause ( ) ;
662
672
let _ = spirc. set_position_ms ( 0 ) ;
@@ -672,12 +682,25 @@ impl MprisPlayerService {
672
682
// If there is no track to play, this has no effect.
673
683
//
674
684
// If `self.can_play` is `false`, attempting to call this method should have no effect.
675
- async fn play ( & self ) {
685
+ async fn play ( & self ) -> zbus :: fdo :: Result < ( ) > {
676
686
debug ! ( "org.mpris.MediaPlayer2.Player::Play" ) ;
677
687
if let Some ( spirc) = & self . spirc {
678
688
let _ = spirc. activate ( ) ;
679
689
let _ = spirc. play ( ) ;
680
690
}
691
+ match ( & self . spirc , & self . metadata . mpris . track_id ) {
692
+ ( Some ( spirc) , Some ( _) ) => {
693
+ let result: Result < ( ) , Error > = ( || {
694
+ spirc. activate ( ) ?;
695
+ spirc. play ( )
696
+ } ) ( ) ;
697
+ result. map_err ( |err| zbus:: fdo:: Error :: Failed ( format ! ( "{err}" ) ) )
698
+ }
699
+ ( Some ( _) , None ) => {
700
+ zbus:: fdo:: Result :: Err ( zbus:: fdo:: Error :: Failed ( String :: from ( "No track" ) ) )
701
+ }
702
+ _ => zbus:: fdo:: Result :: Err ( zbus:: fdo:: Error :: Failed ( String :: from ( "Can't play/pause" ) ) ) ,
703
+ }
681
704
}
682
705
683
706
// Seeks forward in the current track by the specified number of microseconds.
0 commit comments