Crate mpris_server
source ·Expand description
Warning The API is still unstable. Expect breaking changes.
MPRIS Server
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.
Player Usage
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.
use mpris_server::Player;
#[async_std::main]
async fn main() {
let player = Player::builder("com.me.Application")
.can_play(true)
.can_pause(true)
.build()
.unwrap();
player.connect_play_pause(|| {
println!("PlayPause");
});
player.run().await.unwrap();
}Supported Interfaces
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.
org.mpris.MediaPlayer2 and org.mpris.MediaPlayer2.Player
use mpris_server::{export::async_trait, Server};
pub struct MyPlayer;
#[async_trait(?Send)]
impl RootInterface for MyPlayer {
...
}
#[async_trait(?Send)]
impl PlayerInterface for MyPlayer {
...
}
#[async_std::main]
async fn main() {
let server = Server::new("com.me.Application", MyPlayer).unwrap();
server.run().await.unwrap();
}org.mpris.MediaPlayer2.TrackList
use mpris_server::{export::async_trait, Server};
pub struct MyPlayer;
#[async_trait(?Send)]
impl RootInterface for MyPlayer {
...
}
#[async_trait(?Send)]
impl PlayerInterface for MyPlayer {
...
}
#[async_trait(?Send)]
impl TracklistInterface for MyPlayer {
...
}
#[async_std::main]
async fn main() {
let server = Server::new("com.me.Application", MyPlayer).unwrap();
server.run_with_track_list().await.unwrap();
}org.mpris.MediaPlayer2.Playlists
use mpris_server::{export::async_trait, Server};
pub struct MyPlayer;
#[async_trait(?Send)]
impl RootInterface for MyPlayer {
...
}
#[async_trait(?Send)]
impl PlayerInterface for MyPlayer {
...
}
#[async_trait(?Send)]
impl PlaylistsInterface for MyPlayer {
...
}
#[async_std::main]
async fn main() {
let server = Server::new("com.me.Application", MyPlayer).unwrap();
server.run_with_playlists().await.unwrap();
}org.mpris.MediaPlayer2.TrackList and org.mpris.MediaPlayer2.Playlists
use mpris_server::{export::async_trait, Server};
pub struct MyPlayer;
#[async_trait(?Send)]
impl RootInterface for MyPlayer {
...
}
#[async_trait(?Send)]
impl PlayerInterface for MyPlayer {
...
}
#[async_trait(?Send)]
impl PlaylistsInterface for MyPlayer {
...
}
#[async_trait(?Send)]
impl TracklistInterface for MyPlayer {
...
}
#[async_std::main]
async fn main() {
let server = Server::new("com.me.Application", MyPlayer).unwrap();
server.run_with_all().await.unwrap();
}For more examples, see the examples directory.
TODO
- Document public interface
- Replace
TimeInUs,DateTime, andUriwith proper types - Add getter on Metadata
- Consider making Player and Server Sync + Send
- Run server internally, instead of explicit
runmethod
Structs
- Premade mutable object that internally implements
RootInterfaceandPlayerInterface.
Enums
- A repeat / loop status
- A playback state.
- Specifies the ordering of returned playlists.
Traits
Type Aliases
- Date/time fields should be sent as strings in ISO 8601 extended format. If the timezone is known (eg: for xesam:lastPlayed), the internet profile format of ISO 8601, as specified in RFC 3339, should be used.
- A playback rate
- Unique playlist identifier.
- Time in microseconds.
- Unique track identifier.
- URIs should be sent as (UTF-8) strings. Local files should use the “file://” schema.
- Audio volume level