cover works agen

This commit is contained in:
Erica Z 2024-11-05 12:19:33 +01:00
parent 904cf0c55e
commit 4241bbeab4
2 changed files with 25 additions and 8 deletions

View file

@ -178,7 +178,7 @@ impl Client {
}
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> {

View file

@ -62,7 +62,7 @@ mod imp {
mpv_event_loop_handle: RefCell<Option<JoinHandle<()>>>, // really !, not ()
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 {
@ -210,15 +210,30 @@ mod imp {
window.notify("song");
window.imp().buffering_start();
/*
let window = window.clone();
let window2 = window.clone();
let song_id = window.song().unwrap().id();
window
.imp()
.loading_cover_handle
.replace(Some(glib::spawn_future_local(
async move { todo!() },
)))
.map(|handle| handle.abort());*/
.replace(Some(glib::spawn_future_local(async move {
let api = window2.imp().api.borrow().as_ref().unwrap().clone();
let bytes =
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 {
@ -297,6 +312,8 @@ mod imp {
// cancel queued seek always
window.imp().queued_seek.set(None);
window.set_playing_cover_art(None::<gdk::Texture>);
}
_ => event!(Level::DEBUG, "unhandled {event:?}"),