use dbus::blocking::stdintf::org_freedesktop_dbus::PropertiesPropertiesChanged; use dbus::blocking::Connection; use dbus::message::Message; use std::time::Duration; fn main() -> Result<(), Box> { let conn = Connection::new_session()?; let proxy = conn.with_proxy( "org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2", Duration::from_millis(5000), ); let _ = proxy.match_signal( |pc: PropertiesPropertiesChanged, _: &Connection, _: &Message| { pc.changed_properties["Metadata"] .0 .as_iter() .and_then(|mut iter| { // Iterating over a RefArg goes key, value, key, value... Insane honestly. while let Some(key) = iter.next() { let key_str = key.as_str()?; let value = iter.next(); match key_str { "xesam:artist" => { // Variant holding a variant that should just be a Vec<&str> I // believe. This is _the recommended_ way to do this by the author. let inner_value = value?.as_iter()?.next()?.as_iter()?.next()?; let artist = String::from(inner_value.as_str()?); println!("artist: {}", artist); } "xesam:title" => { println!("title: {}", value?.as_iter()?.next()?.as_str()?); } _ => (), } } Some(()) }); true }, ); loop { conn.process(Duration::from_millis(1000))?; } }