Expand description
§mprizzle
An async library for interacting with mpris over D-Bus.
§Usage
use mprizzle::{Mpris, MprisEvent};
#[tokio::main]
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut mpris = Mpris::new_without_options().await?;
let shared_players = mpris.players();
// Start watching for mpris events.
mpris.watch();
while let Ok(event) = mpris.recv().await? {
match event {
// Player Attached / Detached events.
MprisEvent::PlayerAttached(identity) => println!("NEW PLAYER = {}", identity.short()),
MprisEvent::PlayerDetached(identity) => println!("REMOVED PLAYER = {}", identity.short()),
// Player properties changed event.
MprisEvent::PlayerPropertiesChanged(identity) => {
let players = shared_players.lock().await;
if let Some(player) = players.iter().find(|p| *p.identity() == identity) {
println!("PLAYER PROP CHANGED: {} = {:#?}", identity.short(), player.metadata().await?);
}
},
// Player seeked event.
MprisEvent::PlayerSeeked(identity) => {
let players = shared_players.lock().await;
if let Some(_) = players.iter().find(|p| *p.identity() == identity) {
println!("PLAYER SEEKED: {}", identity.short());
}
},
// Player position event.
MprisEvent::PlayerPosition(identity, position) => {
println!("PLAYER POSITION: {} = {}", identity.short(), position.as_secs());
}
}
}
Ok(())
}Structs§
- Mpris
- Represents an MPRIS connection.
- Mpris
Player - Represents an MPRIS media player instance.
- Player
Identity - A struct representing the identity of
crate::player::MprisPlayer. - Player
Metadata - Represents the metadata of an MPRIS media player.
- TrackId
- A custom wrapper type for representing a track identifier.
Enums§
- Loop
Status - Loop status of a player.
- Metadata
Error - Represents errors that can occur in MPRIS Metadata operations.
- Mpris
Error - Represents errors that can occur in MPRIS operations.
- Mpris
Event - Represents events triggered by changes in an MPRIS media player.
- Playback
Status - Playback status of a player.
- Player
Error - Represents errors that can occur in MPRIS Player operations.
Type Aliases§
- Mpris
Result - A shorthand for
Result<T, MprisError>.