Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/CoverCache.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
*/

[SingleInstance]
public class Music.CoverCache : Object {
private HashTable<string, Gdk.Texture> loaded_covers;

construct {
loaded_covers = new HashTable<string, Gdk.Texture> (str_hash, str_equal);
}

public Gdk.Texture? get_cover (string album) {
return loaded_covers.get (album);
}

public Gdk.Texture? add_cover (string album, Gdk.Pixbuf pix) {
Gdk.Texture cover = Gdk.Texture.for_pixbuf (pix);
loaded_covers.insert (album, cover);
return cover;
}
}
13 changes: 12 additions & 1 deletion src/PlaybackManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Music.PlaybackManager : Object {

private dynamic Gst.Element playbin;
private Gst.PbUtils.Discoverer discoverer;
private CoverCache cover_cache;
private uint progress_timer = 0;
private Settings settings;

Expand All @@ -38,6 +39,7 @@ public class Music.PlaybackManager : Object {
private PlaybackManager () {}

construct {
cover_cache = new CoverCache ();
queue_liststore = new ListStore (typeof (AudioObject));

playbin = Gst.ElementFactory.make ("playbin", "playbin");
Expand Down Expand Up @@ -213,12 +215,21 @@ public class Music.PlaybackManager : Object {
audio_object.artist = _("Unknown");
}

string _album;
tag_list.get_string (Gst.Tags.ALBUM, out _album);

string album_key = "%s-%s".printf (_album, audio_object.artist);
audio_object.texture = cover_cache.get_cover (album_key);
if (audio_object.texture != null) {
return;
}

var sample = get_cover_sample (tag_list);
if (sample != null) {
var buffer = sample.get_buffer ();

if (buffer != null) {
audio_object.texture = Gdk.Texture.for_pixbuf (get_pixbuf_from_buffer (buffer));
audio_object.texture = cover_cache.add_cover (album_key, get_pixbuf_from_buffer (buffer));
}
}
} else {
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sources = [
'AudioObject.vala',
'MainWindow.vala',
'PlaybackManager.vala',
'CoverCache.vala',
'DBus/MprisPlayer.vala',
'DBus/MprisRoot.vala',
'Views/NowPlayingView.vala',
Expand Down