fix cover art

This commit is contained in:
Erica Z 2024-10-17 22:36:29 +02:00
parent d17c538ccb
commit d91f945375

View file

@ -57,6 +57,29 @@ class Ui.Window : Adw.ApplicationWindow {
this.playbin.now_playing.connect (() => { this.playbin.now_playing.connect (() => {
api.scrobble.begin (playbin.song.id); api.scrobble.begin (playbin.song.id);
this.play_queue.selection.playbin_select (playbin.play_queue_position); this.play_queue.selection.playbin_select (playbin.play_queue_position);
if (this.cancel_loading_art != null) {
this.cancel_loading_art.cancel ();
}
this.cancel_loading_art = new GLib.Cancellable ();
this.playing_cover_art = Gdk.Paintable.empty (1, 1);
if (playbin.song != null) {
this.cover_art_loading = true;
string song_id = playbin.song.id;
this.api.cover_art.begin (song_id, this.cancel_loading_art, (obj, res) => {
try {
this.playing_cover_art = Gdk.Texture.for_pixbuf (this.api.cover_art.end (res));
this.cover_art_loading = false;
} catch (Error e) {
if (!(e is IOError.CANCELLED)) {
warning ("could not load cover for %s: %s", song_id, e.message);
this.cover_art_loading = false;
}
}
});
}
}); });
this.play_queue.selection.user_selected.connect ((position) => { this.play_queue.selection.user_selected.connect ((position) => {
@ -84,31 +107,6 @@ class Ui.Window : Adw.ApplicationWindow {
this.setup.load (); this.setup.load ();
this.sidebar.select_row (this.sidebar.get_row_at_index (0)); this.sidebar.select_row (this.sidebar.get_row_at_index (0));
this.playbin.notify["current-song"].connect (() => {
if (this.cancel_loading_art != null) {
this.cancel_loading_art.cancel ();
}
this.cancel_loading_art = new GLib.Cancellable ();
this.playing_cover_art = Gdk.Paintable.empty (1, 1);
if (playbin.song != null) {
this.cover_art_loading = true;
string song_id = playbin.song.id;
this.api.cover_art.begin (song_id, this.cancel_loading_art, (obj, res) => {
try {
this.playing_cover_art = Gdk.Texture.for_pixbuf (this.api.cover_art.end (res));
this.cover_art_loading = false;
} catch (Error e) {
if (!(e is IOError.CANCELLED)) {
warning ("could not load cover for %s: %s", song_id, e.message);
this.cover_art_loading = false;
}
}
});
}
});
} }
[GtkCallback] private void on_sidebar_row_activated (Gtk.ListBoxRow row) { [GtkCallback] private void on_sidebar_row_activated (Gtk.ListBoxRow row) {