wip cover art loading

This commit is contained in:
Erica Z 2024-11-05 12:07:30 +01:00
parent df215da372
commit 904cf0c55e
4 changed files with 39 additions and 1 deletions

1
Cargo.lock generated
View file

@ -220,6 +220,7 @@ dependencies = [
"async-channel", "async-channel",
"base16ct", "base16ct",
"bindgen", "bindgen",
"bytes",
"chrono", "chrono",
"event-listener", "event-listener",
"futures", "futures",

View file

@ -7,6 +7,7 @@ edition = "2021"
adw = { version = "0.7.0", package = "libadwaita", features = ["v1_6"] } adw = { version = "0.7.0", package = "libadwaita", features = ["v1_6"] }
async-channel = "2.3.1" async-channel = "2.3.1"
base16ct = { version = "0.2.0", features = ["std"] } base16ct = { version = "0.2.0", features = ["std"] }
bytes = "1.8.0"
chrono = { version = "0.4.38", features = ["serde"] } chrono = { version = "0.4.38", features = ["serde"] }
event-listener = "5.3.1" event-listener = "5.3.1"
futures = "0.3.31" futures = "0.3.31"

View file

@ -181,6 +181,29 @@ impl Client {
self.url(&["rest", "coverArt"], &[("id", id)]) self.url(&["rest", "coverArt"], &[("id", id)])
} }
pub async fn cover_art(&self, id: &str) -> Result<bytes::Bytes, Error> {
let (sender, receiver) = async_channel::bounded(1);
let future = self.client.get(self.cover_art_url(id)).send();
runtime().spawn(async move {
async fn perform(
response: Result<reqwest::Response, reqwest::Error>,
) -> Result<bytes::Bytes, Error> {
Ok(response?.error_for_status()?.bytes().await?)
}
sender
.send(perform(future.await).await)
.await
.expect("could not send cover art bytes back to the main loop");
});
receiver
.recv()
.await
.expect("could not receive cover art bytes from tokio")
}
pub fn stream_url(&self, id: &str) -> url::Url { pub fn stream_url(&self, id: &str) -> url::Url {
self.url(&["rest", "stream"], &[("id", id)]) self.url(&["rest", "stream"], &[("id", id)])
} }

View file

@ -61,6 +61,8 @@ mod imp {
pub(crate) initial_setup_handle: RefCell<Option<JoinHandle<()>>>, pub(crate) initial_setup_handle: RefCell<Option<JoinHandle<()>>>,
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>>>>,
} }
impl Default for Window { impl Default for Window {
@ -111,6 +113,8 @@ mod imp {
initial_setup_handle: Default::default(), initial_setup_handle: Default::default(),
mpv_event_loop_handle: Default::default(), mpv_event_loop_handle: Default::default(),
zbus_executor_loop_handle: Default::default(), zbus_executor_loop_handle: Default::default(),
loading_cover_handle: Default::default(),
} }
} }
} }
@ -205,7 +209,16 @@ mod imp {
event!(Level::INFO, "start file event"); event!(Level::INFO, "start file event");
window.notify("song"); window.notify("song");
window.imp().buffering_start(); window.imp().buffering_start();
// TODO: load cover art
/*
let window = window.clone();
window
.imp()
.loading_cover_handle
.replace(Some(glib::spawn_future_local(
async move { todo!() },
)))
.map(|handle| handle.abort());*/
} }
Event::Hook(event) => match event.reply_userdata { Event::Hook(event) => match event.reply_userdata {