cover art for mpris

This commit is contained in:
Erica Z 2024-10-26 11:38:08 +02:00
parent 347cb55c9d
commit 8e5ac49417
2 changed files with 12 additions and 3 deletions

View file

@ -72,6 +72,8 @@ class MprisPlayer : Object {
[CCode (notify = false)] [CCode (notify = false)]
public bool can_control { get { return true; } } public bool can_control { get { return true; } }
internal Subsonic.Client api { get; set; }
internal MprisPlayer (DBusConnection conn, Playbin playbin) { internal MprisPlayer (DBusConnection conn, Playbin playbin) {
playbin.bind_property ( playbin.bind_property (
"state", "state",
@ -128,7 +130,7 @@ class MprisPlayer : Object {
var metadata = new HashTable<string, Variant> (null, null); var metadata = new HashTable<string, Variant> (null, null);
metadata["mpris:trackid"] = new ObjectPath (@"/eu/callcc/audrey/track/$(song.id)"); metadata["mpris:trackid"] = new ObjectPath (@"/eu/callcc/audrey/track/$(song.id)");
metadata["mpris:length"] = (int64) song.duration * 1000000; metadata["mpris:length"] = (int64) song.duration * 1000000;
// TODO: metadata["mpris:artUrl"] = if (this.api != null) metadata["mpris:artUrl"] = this.api.cover_art_uri (song.id);
metadata["xesam:album"] = song.album; metadata["xesam:album"] = song.album;
metadata["xesam:artist"] = new string[] {song.artist}; metadata["xesam:artist"] = new string[] {song.artist};
if (song.genre != null) metadata["xesam:genre"] = song.genre; if (song.genre != null) metadata["xesam:genre"] = song.genre;

View file

@ -29,6 +29,9 @@ class Ui.Window : Adw.ApplicationWindow {
Object (application: app); Object (application: app);
} }
private Mpris mpris;
private MprisPlayer mpris_player;
private void now_playing (Subsonic.Song song) { private void now_playing (Subsonic.Song song) {
this.song = song; this.song = song;
// api.scrobble.begin (this.song.id); TODO // api.scrobble.begin (this.song.id); TODO
@ -62,8 +65,11 @@ class Ui.Window : Adw.ApplicationWindow {
BusNameOwnerFlags.NONE, BusNameOwnerFlags.NONE,
(conn) => { (conn) => {
try { try {
conn.register_object ("/org/mpris/MediaPlayer2", new Mpris (this)); this.mpris = new Mpris (this);
conn.register_object ("/org/mpris/MediaPlayer2", new MprisPlayer (conn, this.playbin)); this.mpris_player = new MprisPlayer (conn, this.playbin);
conn.register_object ("/org/mpris/MediaPlayer2", this.mpris);
conn.register_object ("/org/mpris/MediaPlayer2", this.mpris_player);
} catch (IOError e) { } catch (IOError e) {
error ("could not register dbus service: %s", e.message); error ("could not register dbus service: %s", e.message);
} }
@ -76,6 +82,7 @@ class Ui.Window : Adw.ApplicationWindow {
this.setup.connected.connect ((api) => { this.setup.connected.connect ((api) => {
this.api = api; this.api = api;
this.playbin.api = api; this.playbin.api = api;
this.mpris_player.api = api;
this.can_click_shuffle_all = true; this.can_click_shuffle_all = true;
}); });
this.setup.load (); this.setup.load ();