Warning The API is still unstable. Expect breaking changes.
Create MPRIS MediaPlayer2 server
To implement a server, this crate provides two flavors: you can either create a custom struct that implements RootInterface
and PlayerInterface
, or you can use the premade mutable Player
struct.
If you want to create a simple player without having to implement the interfaces, you can use the premade Player
struct that implements those interfaces internally. This struct is mutable, automatically emits properties changed signal, and allows you to connect to method calls.
```rust,ignore use mpris_server::Player;
async fn main() { let player = Player::builder("com.me.Application") .canplay(true) .canpause(true) .build() .unwrap();
player.connect_play_pause(|| {
println!("PlayPause");
});
player.run().await.unwrap();
} ```
This library supports all interfaces defined in the MPRIS2 specification. However, the premade Player
struct currently only supports the more commonly used org.mpris.MediaPlayer2
and org.mpris.MediaPlayer2.Player
interfaces.
```rust,ignore use mprisserver::{export::asynctrait, Server};
pub struct MyPlayer;
impl RootInterface for MyPlayer { ... }
impl PlayerInterface for MyPlayer { ... }
async fn main() { let server = Server::new("com.me.Application", MyPlayer).unwrap(); server.run().await.unwrap(); } ```
```rust,ignore use mprisserver::{export::asynctrait, Server};
pub struct MyPlayer;
impl RootInterface for MyPlayer { ... }
impl PlayerInterface for MyPlayer { ... }
impl TracklistInterface for MyPlayer { ... }
async fn main() { let server = Server::new("com.me.Application", MyPlayer).unwrap(); server.runwithtrack_list().await.unwrap(); } ```
```rust,ignore use mprisserver::{export::asynctrait, Server};
pub struct MyPlayer;
impl RootInterface for MyPlayer { ... }
impl PlayerInterface for MyPlayer { ... }
impl PlaylistsInterface for MyPlayer { ... }
async fn main() { let server = Server::new("com.me.Application", MyPlayer).unwrap(); server.runwithplaylists().await.unwrap(); } ```
```rust,ignore use mprisserver::{export::asynctrait, Server};
pub struct MyPlayer;
impl RootInterface for MyPlayer { ... }
impl PlayerInterface for MyPlayer { ... }
impl PlaylistsInterface for MyPlayer { ... }
impl TracklistInterface for MyPlayer { ... }
async fn main() { let server = Server::new("com.me.Application", MyPlayer).unwrap(); server.runwithall().await.unwrap(); } ```
For more examples, see the examples directory.
TimeInUs
, DateTime
, and Uri
with proper typesrun
method