From bf8b02de127342f228dbea88418cebdfe4c06c13 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Wed, 30 Oct 2024 13:09:22 +0100 Subject: [PATCH] volume slider works again --- src/playbin.rs | 14 ++++++++++++++ src/ui/playbar.rs | 19 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/playbin.rs b/src/playbin.rs index 14a0d6c..89d0880 100644 --- a/src/playbin.rs +++ b/src/playbin.rs @@ -22,6 +22,8 @@ mod ffi { pub fn audrey_playbin_get_state(self_: *mut AudreyPlaybin) -> super::state::ffi::State; pub fn audrey_playbin_pause(self_: *mut AudreyPlaybin); pub fn audrey_playbin_play(self_: *mut AudreyPlaybin); + pub fn audrey_playbin_get_volume(self_: *mut AudreyPlaybin) -> std::ffi::c_int; + pub fn audrey_playbin_set_volume(self_: *mut AudreyPlaybin, volume: std::ffi::c_int); } } @@ -53,4 +55,16 @@ impl Playbin { unsafe { ffi::audrey_playbin_play(self.to_glib_none().0) } } + + pub fn get_volume(&self) -> i32 { + use glib::translate::ToGlibPtr; + + unsafe { ffi::audrey_playbin_get_volume(self.to_glib_none().0) } + } + + pub fn set_volume(&self, value: i32) { + use glib::translate::ToGlibPtr; + + unsafe { ffi::audrey_playbin_set_volume(self.to_glib_none().0, value) } + } } diff --git a/src/ui/playbar.rs b/src/ui/playbar.rs index 584ad54..d0ee4ff 100644 --- a/src/ui/playbar.rs +++ b/src/ui/playbar.rs @@ -18,8 +18,8 @@ mod imp { #[property(get, set, default = true)] show_cover_art: Cell, - #[property(get, set)] - volume: Cell, + #[property(get = Self::get_volume, set = Self::set_volume)] + volume: i32, } #[glib::object_subclass] @@ -166,6 +166,21 @@ mod imp { //this.playbin.mute = !this.playbin.mute; todo!() } + + fn get_volume(&self) -> i32 { + let playbin = self.playbin.borrow(); + + match playbin.as_ref() { + None => 100, + Some(playbin) => playbin.get_volume(), + } + } + + fn set_volume(&self, value: i32) { + let playbin = self.playbin.borrow(); + let playbin = playbin.as_ref().unwrap(); + playbin.set_volume(value); + } } }