remove some boilerplate
This commit is contained in:
parent
3b3e3166ca
commit
173494c71f
2 changed files with 49 additions and 40 deletions
|
@ -121,52 +121,44 @@ impl Player {
|
|||
.interface::<_, Self>("/org/mpris/MediaPlayer2")
|
||||
.await?;
|
||||
|
||||
playbin.connect_closure(
|
||||
"new-track",
|
||||
false,
|
||||
glib::closure_local!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, song: &crate::playbin::Song| {
|
||||
let metadata = MetadataMap::from_playbin_song(Some(song));
|
||||
playbin.connect_new_track(glib::clone!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_, song| {
|
||||
let metadata = MetadataMap::from_playbin_song(Some(song));
|
||||
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let mut player = player_ref.get_mut().await;
|
||||
player.metadata = metadata;
|
||||
player
|
||||
.metadata_changed(player_ref.signal_emitter())
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
),
|
||||
);
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let mut player = player_ref.get_mut().await;
|
||||
player.metadata = metadata;
|
||||
player
|
||||
.metadata_changed(player_ref.signal_emitter())
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
));
|
||||
|
||||
playbin.connect_closure(
|
||||
"seeked",
|
||||
false,
|
||||
glib::closure_local!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, position: f64| {
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
player_ref
|
||||
.seeked((position * MICROSECONDS) as i64)
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
),
|
||||
);
|
||||
playbin.connect_seeked(glib::clone!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_, position| {
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
player_ref
|
||||
.seeked((position * MICROSECONDS) as i64)
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
));
|
||||
|
||||
playbin.connect_notify_local(
|
||||
Some("play-queue-length"),
|
||||
glib::clone!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, _| {
|
||||
move |_, _| {
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let player = player_ref.get_mut().await;
|
||||
|
@ -193,7 +185,7 @@ impl Player {
|
|||
glib::clone!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, _| {
|
||||
move |_, _| {
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let player = player_ref.get_mut().await;
|
||||
|
@ -212,7 +204,7 @@ impl Player {
|
|||
glib::clone!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, _| {
|
||||
move |_, _| {
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let player = player_ref.get_mut().await;
|
||||
|
|
|
@ -49,6 +49,7 @@ pub mod ffi {
|
|||
}
|
||||
}
|
||||
|
||||
use adw::prelude::*;
|
||||
use glib::translate::{from_glib, from_glib_none, IntoGlib, ToGlibPtr};
|
||||
use gtk::{gio, glib};
|
||||
|
||||
|
@ -136,4 +137,20 @@ impl Playbin {
|
|||
pub fn play_queue(&self) -> gio::ListModel {
|
||||
unsafe { from_glib_none(ffi::audrey_playbin_get_play_queue(self.to_glib_none().0)) }
|
||||
}
|
||||
|
||||
pub fn connect_new_track<F: Fn(&Self, &Song) + 'static>(&self, f: F) -> glib::SignalHandlerId {
|
||||
self.connect_closure(
|
||||
"new-track",
|
||||
false,
|
||||
glib::closure_local!(|playbin, song| f(playbin, song)),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn connect_seeked<F: Fn(&Self, f64) + 'static>(&self, f: F) -> glib::SignalHandlerId {
|
||||
self.connect_closure(
|
||||
"seeked",
|
||||
false,
|
||||
glib::closure_local!(|playbin, position| f(playbin, position)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue