Skip to content

Commit cae96c8

Browse files
committed
feat(mpris): Notify when volume changed
1 parent 38e5a69 commit cae96c8

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/mpris_event_handler.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ struct MprisPlayerService {
317317
repeat: LoopStatus,
318318
shuffle: bool,
319319
playback_status: PlaybackStatus,
320-
volume: f64,
320+
volume: u16,
321321
metadata: HashMap<String, zbus::zvariant::OwnedValue>,
322322
}
323323

@@ -622,7 +622,7 @@ impl MprisPlayerService {
622622
// an error.
623623
#[zbus(property(emits_changed_signal = "true"))]
624624
async fn volume(&self) -> Volume {
625-
self.volume
625+
self.volume as f64 / u16::MAX as f64
626626
}
627627

628628
#[zbus(property)]
@@ -849,7 +849,7 @@ impl MprisEventHandler {
849849
repeat: LoopStatus::None,
850850
shuffle: false,
851851
playback_status: PlaybackStatus::Stopped,
852-
volume: 1.0,
852+
volume: u16::MAX,
853853
metadata: HashMap::new(),
854854
};
855855

@@ -1166,11 +1166,13 @@ impl MprisTask {
11661166
}
11671167
},
11681168
PlayerEvent::Unavailable { .. } => {}
1169-
PlayerEvent::VolumeChanged {
1170-
// volume
1171-
..
1172-
} => {
1173-
// TODO: Handle volume
1169+
PlayerEvent::VolumeChanged { volume, .. } => {
1170+
let iface_ref = self.mpris_player_iface().await;
1171+
let mut iface = iface_ref.get_mut().await;
1172+
if iface.volume != volume {
1173+
iface.volume = volume;
1174+
iface.volume_changed(iface_ref.signal_context()).await?;
1175+
}
11741176
}
11751177
PlayerEvent::Seeked {
11761178
track_id,

0 commit comments

Comments
 (0)