[][src]Struct mpris::Metadata

pub struct Metadata { /* fields omitted */ }

A structured representation of the Player metadata.

Methods

impl Metadata[src]

pub fn new(track_id: String) -> Self[src]

Create a new Metadata struct with a given track_id.

This is mostly useful for test fixtures and other places where you want to work with mock data.

pub fn clone_without_rest(&self) -> Metadata[src]

Clones Metadata without the rest data.

The rest data uses a non-cloneable type, which makes it impossible to clone a Metadata in the 1.x series of the mpris crate. In version 2.0 this will be fixed.

pub fn track_id(&self) -> &str[src]

The track ID.

Based on mpris:trackId

A unique identity for this track within the context of an MPRIS object.

NOTE: In 2.0 this will be an Option<&str> as players can emit empty metadata when there is no track present. To keep this backwards compatible with 1.x it will instead be an empty string when no track ID is present.

pub fn album_artists(&self) -> Option<&Vec<String>>[src]

A list of artists of the album the track appears on.

Based on xesam:albumArtist

The album artist(s).

pub fn album_name(&self) -> Option<&str>[src]

The name of the album the track appears on.

Based on xesam:album

The album name.

pub fn art_url(&self) -> Option<&str>[src]

An URL to album art of the current track.

Based on mpris:artUrl

The location of an image representing the track or album. Clients should not assume this will continue to exist when the media player stops giving out the URL.

pub fn artists(&self) -> Option<&Vec<String>>[src]

A list of artists of the track.

Based on xesam:artist

The track artist(s).

pub fn auto_rating(&self) -> Option<f64>[src]

Based on xesam:autoRating

An automatically-generated rating, based on things such as how often it has been played. This should be in the range 0.0 to 1.0.

pub fn disc_number(&self) -> Option<i32>[src]

Based on xesam:discNumber

The disc number on the album that this track is from.

pub fn length_in_microseconds(&self) -> Option<u64>[src]

The duration of the track, in microseconds

Based on mpris:length

The duration of the track in microseconds.

pub fn length(&self) -> Option<Duration>[src]

The duration of the track, as a Duration

Based on mpris:length.

pub fn title(&self) -> Option<&str>[src]

The name of the track.

Based on xesam:title

The track title.

pub fn track_number(&self) -> Option<i32>[src]

The track number on the disc of the album the track appears on.

Based on xesam:trackNumber

The track number on the album disc.

pub fn url(&self) -> Option<&str>[src]

A URL to the media being played.

Based on xesam:url

The location of the media file.

pub fn rest(&self) -> &HashMap<String, Variant<Box<dyn RefArg>>>[src]

Deprecated since 1.1.0:

This function will be removed or change signature in 2.0. See rest_hash for a version more closely related to how 2.0 will work.

Remaining metadata that has not been parsed into one of the other fields of the Metadata, if any.

NOTE: This method is deprecated and will be removed in version 2.0. See rest_hash or Player::get_metadata_hash for better alternatives.

As an example, if the media player exposed xesam:composer, then you could read that String like this:

use dbus::arg::RefArg;
if let Some(name) = metadata.rest().get("xesam:composer").and_then(|v| v.as_str()) {
    println!("Composed by: {}", name)
}

pub fn rest_hash(&self) -> HashMap<String, Value>[src]

Remaining metadata that has not been parsed into one of the other fields of the Metadata, if any.

NOTE: This method will be renamed and reworked in version 2.0 in order to replace rest. Note that this method will likely become cheaper at that point.

NOTE: This method returns an owned value in the 1.x series for backwards-compatibility reasons. That means that this method is expensive to call and you should reuse the value if possible.

NOTE: This method will not be able to return all possible fields and types. There is an escape hatch at Player::get_metadata_hash that will be able to convert all of the values, but it is entirely divorced from the 1.x version of Metadata.

As an example, if the media player exposed xesam:composer, then you could read that String like this:

use mpris::{Metadata, MetadataValue};
let rest_hash = metadata.rest_hash();
let composer = rest_hash.get("xesam:composer");
match composer {
    Some(&MetadataValue::String(ref name)) => println!("Composed by: {}", name),
    Some(value) => println!("xesam:composer had an unexpected type: {:?}", value.kind()),
    None => println!("Composer is not set"),
}

Trait Implementations

impl Default for Metadata[src]

impl Debug for Metadata[src]

Auto Trait Implementations

impl !Send for Metadata

impl !Sync for Metadata

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]