Compare commits

..

3 commits

Author SHA1 Message Date
8ccf9cfccb joiney 2024-11-19 21:57:18 +01:00
5cd88a0711 m'pris 2024-11-19 21:52:44 +01:00
162a151595 emit mpris seeked signal 2024-11-19 21:41:06 +01:00
2 changed files with 47 additions and 5 deletions

View file

@ -6,7 +6,7 @@ use tracing::{event, Level};
use zbus::object_server::{InterfaceRef, SignalEmitter}; use zbus::object_server::{InterfaceRef, SignalEmitter};
use zbus::zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Value}; use zbus::zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Value};
const MICROSECONDS: f64 = 1e6; // in a second pub const MICROSECONDS: f64 = 1e6; // in a second
#[derive(Default)] #[derive(Default)]
pub struct MetadataMap { pub struct MetadataMap {
@ -222,6 +222,18 @@ impl Player {
*/ */
} }
pub async fn on_playlist_count_changed(
&self,
emitter: &SignalEmitter<'_>,
) -> Result<(), zbus::fdo::Error> {
futures::try_join!(
self.can_go_next_changed(emitter),
self.can_go_previous_changed(emitter),
self.can_play_changed(emitter),
)?;
Ok(())
}
fn window(&self) -> Window { fn window(&self) -> Window {
self.window.upgrade().unwrap() self.window.upgrade().unwrap()
} }
@ -287,7 +299,7 @@ impl Player {
} }
#[zbus(signal)] #[zbus(signal)]
async fn seeked(emitter: &SignalEmitter<'_>, position: i64) -> zbus::Result<()>; pub async fn seeked(emitter: &SignalEmitter<'_>, position: i64) -> zbus::Result<()>;
#[zbus(property)] #[zbus(property)]
fn playback_status(&self) -> String { fn playback_status(&self) -> String {
@ -370,17 +382,17 @@ impl Player {
#[zbus(property)] #[zbus(property)]
fn can_go_next(&self) -> bool { fn can_go_next(&self) -> bool {
true // TODO self.window().playlist_count() > 0
} }
#[zbus(property)] #[zbus(property)]
fn can_go_previous(&self) -> bool { fn can_go_previous(&self) -> bool {
true // TODO self.window().playlist_count() > 0
} }
#[zbus(property)] #[zbus(property)]
fn can_play(&self) -> bool { fn can_play(&self) -> bool {
true // TODO self.window().playlist_count() > 0
} }
#[zbus(property)] #[zbus(property)]

View file

@ -597,6 +597,18 @@ mod imp {
6 => { 6 => {
assert_eq!(event.name, "playlist-count"); assert_eq!(event.name, "playlist-count");
self.obj().notify("playlist-count"); self.obj().notify("playlist-count");
// mpris can-go-next depends on this
if let Some(iface_ref) = self.mpris_player() {
glib::spawn_future_local(async move {
iface_ref
.get()
.await
.on_playlist_count_changed(iface_ref.signal_emitter())
.await
.unwrap();
});
}
} }
7 => { 7 => {
@ -807,6 +819,24 @@ mod imp {
self.obj().notify("time-pos"); self.obj().notify("time-pos");
self.buffering_start(); self.buffering_start();
let time_pos = self.obj().time_pos();
if let Some(iface_ref) = self.mpris_player() {
glib::spawn_future_local(async move {
match mpris::Player::seeked(
iface_ref.signal_emitter(),
(time_pos * mpris::player::MICROSECONDS) as i64,
)
.await
{
Ok(()) => {}
Err(err) => event!(
Level::ERROR,
"could not notify seek through mpris interface: {err}"
),
}
});
}
} }
fn on_playback_restart(&self) { fn on_playback_restart(&self) {