todo mpris player server

This commit is contained in:
Erica Z 2024-11-01 12:45:01 +01:00
parent b069a2ddb7
commit e1af996482
2 changed files with 142 additions and 18 deletions

View file

@ -25,6 +25,8 @@ mod imp {
window.present(); window.present();
let mpris = crate::Mpris::new(&window); let mpris = crate::Mpris::new(&window);
let mpris_player = crate::mpris::Player::new();
glib::spawn_future_local(async { glib::spawn_future_local(async {
// run this in glib's main loop // run this in glib's main loop
let conn = zbus::connection::Builder::session() let conn = zbus::connection::Builder::session()
@ -34,6 +36,8 @@ mod imp {
.expect("could not register name in session bus") .expect("could not register name in session bus")
.serve_at("/org/mpris/MediaPlayer2", mpris) .serve_at("/org/mpris/MediaPlayer2", mpris)
.expect("could not serve mpris") .expect("could not serve mpris")
.serve_at("/org/mpris/MediaPlayer2", mpris_player)
.expect("could not serve mpris player")
.build() .build()
.await .await
.expect("could not build dbus connection"); .expect("could not build dbus connection");

View file

@ -1,27 +1,147 @@
mod ffi { use zbus::object_server::SignalEmitter;
use gtk::glib; use zbus::zvariant::{ObjectPath, Value};
#[repr(C)] pub struct Player {}
pub struct AudreyMprisPlayer {
parent_instance: glib::gobject_ffi::GObject,
}
#[repr(C)] impl Player {
pub struct AudreyMprisClassPlayer { pub fn new() -> Self {
parent_class: glib::gobject_ffi::GObjectClass, Self {}
}
extern "C" {
pub fn audrey_mpris_player_get_type() -> glib::ffi::GType;
} }
} }
use gtk::glib; #[zbus::interface(name = "org.mpris.MediaPlayer2.Player")]
impl Player {
fn next(&self) {
todo!()
}
glib::wrapper! { fn previous(&self) {
pub struct Player(Object<ffi::AudreyMprisPlayer, ffi::AudreyMprisClassPlayer>); todo!()
}
match fn { fn pause(&self) {
type_ => || ffi::audrey_mpris_player_get_type(), todo!()
}
fn play_pause(&self) {
todo!()
}
fn stop(&self) {
todo!()
}
fn play(&self) {
todo!()
}
fn seek(&self, _offset: i64) {
todo!()
}
fn set_position(&self, _track_id: ObjectPath<'_>, _position: i64) {
todo!()
}
fn open_uri(&self, _s: &str) {
todo!()
}
#[zbus(signal)]
async fn seeked(signal_emitter: &SignalEmitter<'_>, position: i64) -> zbus::Result<()>;
#[zbus(property)]
fn playback_status(&self) -> String {
"Stopped".into() // TODO
}
#[zbus(property)]
fn loop_status(&self) -> String {
"None".into() // TODO
}
#[zbus(property)]
fn set_loop_status(&self, _loop_status: &str) {
todo!()
}
#[zbus(property)]
fn playback_rate(&self) -> f64 {
1.0
}
#[zbus(property)]
fn set_playback_rate(&self, _playback_rate: f64) {
todo!()
}
#[zbus(property)]
fn shuffle(&self) -> zbus::fdo::Result<bool> {
Err(zbus::fdo::Error::NotSupported("Shuffle".into()))
}
#[zbus(property)]
fn set_shuffle(&self, _shuffle: bool) {
todo!()
}
#[zbus(property)]
fn metadata(&self) -> Vec<(String, Value)> {
vec![] // TODO
}
#[zbus(property)]
fn volume(&self) -> f64 {
1.0 // TODO
}
#[zbus(property)]
fn set_volume(&self, _volume: f64) {
todo!()
}
#[zbus(property(emits_changed_signal = "false"))]
fn position(&self) -> i64 {
0 // TODO
}
#[zbus(property)]
fn minimum_rate(&self) -> f64 {
1.0
}
#[zbus(property)]
fn maximum_rate(&self) -> f64 {
1.0
}
#[zbus(property)]
fn can_go_next(&self) -> bool {
false // TODO
}
#[zbus(property)]
fn can_go_previous(&self) -> bool {
false // TODO
}
#[zbus(property)]
fn can_play(&self) -> bool {
false // TODO
}
#[zbus(property)]
fn can_pause(&self) -> bool {
false // TODO
}
#[zbus(property)]
fn can_seek(&self) -> bool {
false // TODO
}
#[zbus(property(emits_changed_signal = "const"))]
fn can_control(&self) -> bool {
false // TODO
} }
} }