doobs_mpris/lib.rs
1// SPDX-License-Identifier: MPL-2.0
2
3//! This crate provides [zbus](https://github.com/z-galaxy/zbus/) bindings for the [MPRIS D-Bus Interface Specification](https://specifications.freedesktop.org/mpris/latest/).
4//!
5//! It can be used to connect to and discover existing media players that implement the MPRIS specification, as well as adding MPRIS-support to your own media player.
6//!
7//! The main goal is to make working with MPRIS as simple as possible by providing custom types and default implementations:
8//!
9//! * LoopStatus, PlaybackStatus and PlaylistOrdering are exposed as enums instead of strings
10//! * durations (playback position and seeked amount) are exposed as `SignedDuration`s instead of microseconds, so you can easily convert them to and from your desired type
11//! * instead of directly implementing the zbus interfaces there is a `Provider` trait for each D-Bus interface
12//! * these contain default implementations for all D-Bus methods and properties that aren't necessary for a read-only media player to make it easy to get started quickly
13//!
14//! # Connecting to an existing player
15//!
16//! ```no_run
17//! # use doobs_mpris::binding::PlayerProxy;
18//! # #[tokio::main]
19//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
20//! let conn = zbus::Connection::session().await?;
21//! let proxy = PlayerProxy::new(&conn, "org.mpris.MediaPlayer2.some_mpris_player").await?;
22//! proxy.play_pause().await?;
23//! # Ok(())
24//! # }
25//! ```
26//!
27//! There are also [examples](https://github.com/teatwig/doobs-mpris/tree/main/examples/) for automatically discovering players.
28//!
29//! # Creating a new player
30//!
31//! See the [player example](https://github.com/teatwig/doobs-mpris/tree/main/examples/player.rs).
32
33pub mod binding;
34
35mod enumerator;
36pub use enumerator::*;
37
38mod error;
39pub use error::*;
40
41mod media_player;
42pub use media_player::*;
43
44mod player;
45pub use player::*;
46
47mod playlists;
48pub use playlists::*;
49
50mod track_list;
51pub use track_list::*;
52
53pub mod types;
54
55pub(crate) fn handle_optional<T>(input: zbus::Result<T>) -> error::Result<Option<T>> {
56 match input {
57 Ok(input) => Ok(Some(input)),
58 Err(zbus::Error::FDO(fdo_error))
59 if matches!(*fdo_error, zbus::fdo::Error::NotSupported(_)) =>
60 {
61 Ok(None)
62 }
63 Err(err) => Err(error::Error::from(err)),
64 }
65}