Mpris fixes/improvements
This commit is contained in:
parent
414cbeba0f
commit
fdf36c4a66
1 changed files with 13 additions and 6 deletions
|
|
@ -136,7 +136,7 @@ impl MprisPlayer {
|
||||||
obj.inner().player.set(player);
|
obj.inner().player.set(player);
|
||||||
|
|
||||||
glib::MainContext::default().spawn_local(clone!(@strong obj => async move {
|
glib::MainContext::default().spawn_local(clone!(@strong obj => async move {
|
||||||
if stream.next().await.is_some() {
|
while stream.next().await.is_some() {
|
||||||
obj.update();
|
obj.update();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
@ -166,6 +166,7 @@ impl MprisPlayer {
|
||||||
drop(image_uri);
|
drop(image_uri);
|
||||||
|
|
||||||
let pixbuf = async {
|
let pixbuf = async {
|
||||||
|
// TODO: Security?
|
||||||
let file = gio::File::for_uri(&arturl?);
|
let file = gio::File::for_uri(&arturl?);
|
||||||
let stream = file.read_async_future(glib::PRIORITY_DEFAULT).await.ok()?;
|
let stream = file.read_async_future(glib::PRIORITY_DEFAULT).await.ok()?;
|
||||||
gdk_pixbuf::Pixbuf::from_stream_async_future(&stream)
|
gdk_pixbuf::Pixbuf::from_stream_async_future(&stream)
|
||||||
|
|
@ -180,10 +181,8 @@ impl MprisPlayer {
|
||||||
|
|
||||||
fn update(&self) {
|
fn update(&self) {
|
||||||
let player = &self.inner().player;
|
let player = &self.inner().player;
|
||||||
|
|
||||||
// XXX status
|
|
||||||
let (status, metadata) = match (player.cached_playback_status(), player.cached_metadata()) {
|
let (status, metadata) = match (player.cached_playback_status(), player.cached_metadata()) {
|
||||||
(Ok(Some(status)), Ok(Some(metadata))) => (status, Metadata(metadata)),
|
(Ok(Some(status)), Ok(Some(metadata))) => (status, metadata),
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -215,7 +214,15 @@ impl MprisPlayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Metadata(HashMap<String, OwnedValue>);
|
pub struct Metadata(HashMap<String, OwnedValue>);
|
||||||
|
|
||||||
|
impl TryFrom<OwnedValue> for Metadata {
|
||||||
|
type Error = zbus::Error;
|
||||||
|
|
||||||
|
fn try_from(value: OwnedValue) -> zbus::Result<Self> {
|
||||||
|
Ok(Self(value.try_into()?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Metadata {
|
impl Metadata {
|
||||||
fn lookup<'a, T: TryFrom<OwnedValue>>(&self, key: &str) -> Option<T> {
|
fn lookup<'a, T: TryFrom<OwnedValue>>(&self, key: &str) -> Option<T> {
|
||||||
|
|
@ -245,7 +252,7 @@ impl Metadata {
|
||||||
)]
|
)]
|
||||||
trait Player {
|
trait Player {
|
||||||
#[dbus_proxy(property)]
|
#[dbus_proxy(property)]
|
||||||
fn metadata(&self) -> zbus::Result<HashMap<String, OwnedValue>>;
|
fn metadata(&self) -> zbus::Result<Metadata>;
|
||||||
|
|
||||||
#[dbus_proxy(property)]
|
#[dbus_proxy(property)]
|
||||||
fn playback_status(&self) -> zbus::Result<String>;
|
fn playback_status(&self) -> zbus::Result<String>;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue