unfuck playbar
This commit is contained in:
parent
f8015fbe10
commit
ab354a35c0
3 changed files with 69 additions and 39 deletions
|
@ -25,9 +25,18 @@ mod ffi {
|
||||||
pub fn audrey_playbin_get_volume(self_: *mut AudreyPlaybin) -> std::ffi::c_int;
|
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);
|
pub fn audrey_playbin_set_volume(self_: *mut AudreyPlaybin, volume: std::ffi::c_int);
|
||||||
pub fn audrey_playbin_seek(self_: *mut AudreyPlaybin, position: f64);
|
pub fn audrey_playbin_seek(self_: *mut AudreyPlaybin, position: f64);
|
||||||
|
pub fn audrey_playbin_go_to_next_track(self_: *mut AudreyPlaybin);
|
||||||
|
pub fn audrey_playbin_go_to_prev_track(self_: *mut AudreyPlaybin);
|
||||||
|
pub fn audrey_playbin_get_position(self_: *mut AudreyPlaybin) -> f64;
|
||||||
|
pub fn audrey_playbin_get_duration(self_: *mut AudreyPlaybin) -> f64;
|
||||||
|
pub fn audrey_playbin_get_mute(self_: *mut AudreyPlaybin) -> glib::ffi::gboolean;
|
||||||
|
pub fn audrey_playbin_set_mute(self_: *mut AudreyPlaybin, mute: glib::ffi::gboolean);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use glib::translate::from_glib;
|
||||||
|
use glib::translate::IntoGlib;
|
||||||
|
use glib::translate::ToGlibPtr;
|
||||||
use gtk::glib;
|
use gtk::glib;
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
|
@ -39,39 +48,51 @@ glib::wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Playbin {
|
impl Playbin {
|
||||||
pub fn get_state(&self) -> State {
|
pub fn state(&self) -> State {
|
||||||
use glib::translate::ToGlibPtr;
|
|
||||||
|
|
||||||
unsafe { glib::translate::from_glib(ffi::audrey_playbin_get_state(self.to_glib_none().0)) }
|
unsafe { glib::translate::from_glib(ffi::audrey_playbin_get_state(self.to_glib_none().0)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pause(&self) {
|
pub fn pause(&self) {
|
||||||
use glib::translate::ToGlibPtr;
|
|
||||||
|
|
||||||
unsafe { ffi::audrey_playbin_pause(self.to_glib_none().0) }
|
unsafe { ffi::audrey_playbin_pause(self.to_glib_none().0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play(&self) {
|
pub fn play(&self) {
|
||||||
use glib::translate::ToGlibPtr;
|
|
||||||
|
|
||||||
unsafe { ffi::audrey_playbin_play(self.to_glib_none().0) }
|
unsafe { ffi::audrey_playbin_play(self.to_glib_none().0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_volume(&self) -> i32 {
|
pub fn volume(&self) -> i32 {
|
||||||
use glib::translate::ToGlibPtr;
|
|
||||||
|
|
||||||
unsafe { ffi::audrey_playbin_get_volume(self.to_glib_none().0) }
|
unsafe { ffi::audrey_playbin_get_volume(self.to_glib_none().0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_volume(&self, value: i32) {
|
pub fn set_volume(&self, value: i32) {
|
||||||
use glib::translate::ToGlibPtr;
|
|
||||||
|
|
||||||
unsafe { ffi::audrey_playbin_set_volume(self.to_glib_none().0, value) }
|
unsafe { ffi::audrey_playbin_set_volume(self.to_glib_none().0, value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn seek(&self, position: f64) {
|
pub fn seek(&self, position: f64) {
|
||||||
use glib::translate::ToGlibPtr;
|
|
||||||
|
|
||||||
unsafe { ffi::audrey_playbin_seek(self.to_glib_none().0, position) }
|
unsafe { ffi::audrey_playbin_seek(self.to_glib_none().0, position) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn go_to_next_track(&self) {
|
||||||
|
unsafe { ffi::audrey_playbin_go_to_next_track(self.to_glib_none().0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn go_to_prev_track(&self) {
|
||||||
|
unsafe { ffi::audrey_playbin_go_to_prev_track(self.to_glib_none().0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn position(&self) -> f64 {
|
||||||
|
unsafe { ffi::audrey_playbin_get_position(self.to_glib_none().0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn duration(&self) -> f64 {
|
||||||
|
unsafe { ffi::audrey_playbin_get_duration(self.to_glib_none().0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mute(&self) -> bool {
|
||||||
|
unsafe { from_glib(ffi::audrey_playbin_get_mute(self.to_glib_none().0)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_mute(&self, mute: bool) {
|
||||||
|
unsafe { ffi::audrey_playbin_set_mute(self.to_glib_none().0, mute.into_glib()) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ glib::wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Song {
|
impl Song {
|
||||||
pub fn get_title(&self) -> std::borrow::Cow<'_, str> {
|
pub fn title(&self) -> std::borrow::Cow<'_, str> {
|
||||||
use glib::translate::ToGlibPtr;
|
use glib::translate::ToGlibPtr;
|
||||||
|
|
||||||
// TODO: memory management....
|
// TODO: memory management....
|
||||||
|
@ -46,7 +46,7 @@ impl Song {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_artist(&self) -> std::borrow::Cow<'_, str> {
|
pub fn artist(&self) -> std::borrow::Cow<'_, str> {
|
||||||
use glib::translate::ToGlibPtr;
|
use glib::translate::ToGlibPtr;
|
||||||
|
|
||||||
// TODO: memory management....
|
// TODO: memory management....
|
||||||
|
@ -56,7 +56,7 @@ impl Song {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_album(&self) -> std::borrow::Cow<'_, str> {
|
pub fn album(&self) -> std::borrow::Cow<'_, str> {
|
||||||
use glib::translate::ToGlibPtr;
|
use glib::translate::ToGlibPtr;
|
||||||
|
|
||||||
// TODO: memory management....
|
// TODO: memory management....
|
||||||
|
|
|
@ -18,8 +18,8 @@ mod imp {
|
||||||
#[property(get, set, default = true)]
|
#[property(get, set, default = true)]
|
||||||
show_cover_art: Cell<bool>,
|
show_cover_art: Cell<bool>,
|
||||||
|
|
||||||
#[property(get = Self::get_volume, set = Self::set_volume)]
|
#[property(type = i32, get = Self::volume, set = Self::set_volume)]
|
||||||
_volume: i32,
|
_volume: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
@ -51,7 +51,7 @@ mod imp {
|
||||||
fn song_title(&self, song: Option<&crate::playbin::Song>) -> String {
|
fn song_title(&self, song: Option<&crate::playbin::Song>) -> String {
|
||||||
match song {
|
match song {
|
||||||
None => "".to_owned(),
|
None => "".to_owned(),
|
||||||
Some(song) => song.get_title().to_string(),
|
Some(song) => song.title().to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ mod imp {
|
||||||
fn song_artist(&self, song: Option<&crate::playbin::Song>) -> String {
|
fn song_artist(&self, song: Option<&crate::playbin::Song>) -> String {
|
||||||
match song {
|
match song {
|
||||||
None => "".to_owned(),
|
None => "".to_owned(),
|
||||||
Some(song) => song.get_artist().to_string(),
|
Some(song) => song.artist().to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ mod imp {
|
||||||
fn song_album(&self, song: Option<&crate::playbin::Song>) -> String {
|
fn song_album(&self, song: Option<&crate::playbin::Song>) -> String {
|
||||||
match song {
|
match song {
|
||||||
None => "".to_owned(),
|
None => "".to_owned(),
|
||||||
Some(song) => song.get_album().to_string(),
|
Some(song) => song.album().to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,32 +120,40 @@ mod imp {
|
||||||
|
|
||||||
#[template_callback]
|
#[template_callback]
|
||||||
fn on_skip_forward_clicked(&self) {
|
fn on_skip_forward_clicked(&self) {
|
||||||
// this.playbin.go_to_next_track ();
|
let playbin = self.playbin.borrow();
|
||||||
todo!()
|
let playbin = playbin.as_ref().unwrap();
|
||||||
|
playbin.go_to_next_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[template_callback]
|
#[template_callback]
|
||||||
fn on_skip_backward_clicked(&self) {
|
fn on_skip_backward_clicked(&self) {
|
||||||
// this.playbin.go_to_prev_track ();
|
let playbin = self.playbin.borrow();
|
||||||
todo!()
|
let playbin = playbin.as_ref().unwrap();
|
||||||
|
playbin.go_to_prev_track();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[template_callback]
|
#[template_callback]
|
||||||
fn seek_backward(&self) {
|
fn seek_backward(&self) {
|
||||||
|
let playbin = self.playbin.borrow();
|
||||||
|
let playbin = playbin.as_ref().unwrap();
|
||||||
// 10 seconds
|
// 10 seconds
|
||||||
// double new_position = playbin.position - 10.0;
|
let mut new_position = playbin.position() - 10.0;
|
||||||
// if (new_position < 0.0) new_position = 0.0;
|
if new_position < 0.0 {
|
||||||
// this.playbin.seek (new_position);
|
new_position = 0.0;
|
||||||
todo!()
|
}
|
||||||
|
playbin.seek(new_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[template_callback]
|
#[template_callback]
|
||||||
fn seek_forward(&self) {
|
fn seek_forward(&self) {
|
||||||
|
let playbin = self.playbin.borrow();
|
||||||
|
let playbin = playbin.as_ref().unwrap();
|
||||||
// 10 seconds
|
// 10 seconds
|
||||||
// double new_position = playbin.position + 10.0;
|
let mut new_position = playbin.position() + 10.0;
|
||||||
// if (new_position > this.playbin.duration) new_position = this.playbin.duration;
|
if new_position > playbin.duration() {
|
||||||
// this.playbin.seek (new_position);
|
new_position = playbin.duration();
|
||||||
todo!()
|
}
|
||||||
|
playbin.seek(new_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[template_callback]
|
#[template_callback]
|
||||||
|
@ -153,7 +161,7 @@ mod imp {
|
||||||
let playbin = self.playbin.borrow();
|
let playbin = self.playbin.borrow();
|
||||||
let playbin = playbin.as_ref().unwrap();
|
let playbin = playbin.as_ref().unwrap();
|
||||||
|
|
||||||
if playbin.get_state() == crate::playbin::State::Playing {
|
if playbin.state() == crate::playbin::State::Playing {
|
||||||
playbin.pause();
|
playbin.pause();
|
||||||
} else {
|
} else {
|
||||||
playbin.play();
|
playbin.play();
|
||||||
|
@ -162,16 +170,17 @@ mod imp {
|
||||||
|
|
||||||
#[template_callback]
|
#[template_callback]
|
||||||
fn on_mute_toggle(&self) {
|
fn on_mute_toggle(&self) {
|
||||||
//this.playbin.mute = !this.playbin.mute;
|
let playbin = self.playbin.borrow();
|
||||||
todo!()
|
let playbin = playbin.as_ref().unwrap();
|
||||||
|
playbin.set_mute(!playbin.mute());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_volume(&self) -> i32 {
|
fn volume(&self) -> i32 {
|
||||||
let playbin = self.playbin.borrow();
|
let playbin = self.playbin.borrow();
|
||||||
|
|
||||||
match playbin.as_ref() {
|
match playbin.as_ref() {
|
||||||
None => 100,
|
None => 100,
|
||||||
Some(playbin) => playbin.get_volume(),
|
Some(playbin) => playbin.volume(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue