cover works agen
This commit is contained in:
parent
904cf0c55e
commit
4241bbeab4
2 changed files with 25 additions and 8 deletions
|
@ -178,7 +178,7 @@ impl Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cover_art_url(&self, id: &str) -> url::Url {
|
pub fn cover_art_url(&self, id: &str) -> url::Url {
|
||||||
self.url(&["rest", "coverArt"], &[("id", id)])
|
self.url(&["rest", "getCoverArt"], &[("id", id)])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn cover_art(&self, id: &str) -> Result<bytes::Bytes, Error> {
|
pub async fn cover_art(&self, id: &str) -> Result<bytes::Bytes, Error> {
|
||||||
|
|
|
@ -62,7 +62,7 @@ mod imp {
|
||||||
mpv_event_loop_handle: RefCell<Option<JoinHandle<()>>>, // really !, not ()
|
mpv_event_loop_handle: RefCell<Option<JoinHandle<()>>>, // really !, not ()
|
||||||
zbus_executor_loop_handle: RefCell<Option<JoinHandle<()>>>, // same
|
zbus_executor_loop_handle: RefCell<Option<JoinHandle<()>>>, // same
|
||||||
|
|
||||||
loading_cover_handle: RefCell<Option<JoinHandle<Option<gdk::Paintable>>>>,
|
loading_cover_handle: RefCell<Option<JoinHandle<()>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Window {
|
impl Default for Window {
|
||||||
|
@ -210,15 +210,30 @@ mod imp {
|
||||||
window.notify("song");
|
window.notify("song");
|
||||||
window.imp().buffering_start();
|
window.imp().buffering_start();
|
||||||
|
|
||||||
/*
|
let window2 = window.clone();
|
||||||
let window = window.clone();
|
let song_id = window.song().unwrap().id();
|
||||||
window
|
window
|
||||||
.imp()
|
.imp()
|
||||||
.loading_cover_handle
|
.loading_cover_handle
|
||||||
.replace(Some(glib::spawn_future_local(
|
.replace(Some(glib::spawn_future_local(async move {
|
||||||
async move { todo!() },
|
let api = window2.imp().api.borrow().as_ref().unwrap().clone();
|
||||||
)))
|
let bytes =
|
||||||
.map(|handle| handle.abort());*/
|
api
|
||||||
|
.cover_art(&song_id)
|
||||||
|
.await
|
||||||
|
.expect("could not load cover art for song {song_id}");
|
||||||
|
|
||||||
|
match window2.song() {
|
||||||
|
Some(song) if song.id() == song_id => {
|
||||||
|
let texture = gdk::Texture::from_bytes(&glib::Bytes::from_owned(bytes)).expect(
|
||||||
|
"could not create texture from cover art for {song_id}",
|
||||||
|
);
|
||||||
|
window2.set_playing_cover_art(Some(texture));
|
||||||
|
}
|
||||||
|
_ => { event!(Level::WARN, "was too late to fetch cover for song {song_id}") },
|
||||||
|
}
|
||||||
|
})))
|
||||||
|
.map(|handle| handle.abort());
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::Hook(event) => match event.reply_userdata {
|
Event::Hook(event) => match event.reply_userdata {
|
||||||
|
@ -297,6 +312,8 @@ mod imp {
|
||||||
|
|
||||||
// cancel queued seek always
|
// cancel queued seek always
|
||||||
window.imp().queued_seek.set(None);
|
window.imp().queued_seek.set(None);
|
||||||
|
|
||||||
|
window.set_playing_cover_art(None::<gdk::Texture>);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => event!(Level::DEBUG, "unhandled {event:?}"),
|
_ => event!(Level::DEBUG, "unhandled {event:?}"),
|
||||||
|
|
Loading…
Reference in a new issue