This commit is contained in:
Erica Z 2024-10-18 22:55:38 +02:00
parent f8ad4cd36d
commit 8bf0e13ba9
3 changed files with 14 additions and 17 deletions

View file

@ -36,10 +36,8 @@ class Playbin : GLib.Object {
} }
public uint play_queue_position { get; private set; } public uint play_queue_position { get; private set; }
public Subsonic.Song? song { get; private set; }
private bool notify_next_playing; public signal void now_playing (Subsonic.Song now, Subsonic.Song? next);
public signal void now_playing ();
public signal void stopped (); public signal void stopped ();
public double position { get; private set; default = 0.0; } public double position { get; private set; default = 0.0; }
@ -118,14 +116,14 @@ class Playbin : GLib.Object {
if (data.parse_int64 () < 0) { if (data.parse_int64 () < 0) {
debug ("playlist-pos is null, sending stopped event"); debug ("playlist-pos is null, sending stopped event");
this.play_queue_position = this.play_queue.get_n_items (); this.play_queue_position = this.play_queue.get_n_items ();
this.song = null;
this.state = PlaybinState.STOPPED; this.state = PlaybinState.STOPPED;
this.stopped (); this.stopped ();
} else { } else {
this.play_queue_position = (uint) data.parse_int64 (); this.play_queue_position = (uint) data.parse_int64 ();
debug (@"playlist-pos has been updated to $(this.play_queue_position)"); debug (@"playlist-pos has been updated to $(this.play_queue_position)");
this.song = (Subsonic.Song) this.play_queue.get_item (this.play_queue_position); this.now_playing (
this.now_playing (); (Subsonic.Song) this.play_queue.get_item (this.play_queue_position),
(Subsonic.Song?) this.play_queue.get_item (this.play_queue_position+1));
} }
break; break;
@ -169,10 +167,6 @@ class Playbin : GLib.Object {
{ {
assert (this.mpv.command ({"playlist-play-index", position.to_string ()}) >= 0); assert (this.mpv.command ({"playlist-play-index", position.to_string ()}) >= 0);
this.state = PlaybinState.PLAYING; this.state = PlaybinState.PLAYING;
this.play_queue_position = position;
this.song = (Subsonic.Song) this.play_queue.get_item (position);
this.now_playing ();
this.notify_next_playing = false;
} }
public void pause () { public void pause () {

View file

@ -103,21 +103,21 @@ template $UiWindow: Adw.ApplicationWindow {
styles [ "heading" ] styles [ "heading" ]
xalign: 0; xalign: 0;
halign: start; halign: start;
label: bind $song_title (template.playbin as <$Playbin>.song) as <string>; label: bind $song_title (template.song) as <string>;
ellipsize: end; ellipsize: end;
} }
Label { Label {
styles [ "caption" ] styles [ "caption" ]
xalign: 0; xalign: 0;
label: bind $song_artist (template.playbin as <$Playbin>.song) as <string>; label: bind $song_artist (template.song) as <string>;
ellipsize: end; ellipsize: end;
} }
Label { Label {
styles [ "caption" ] styles [ "caption" ]
xalign: 0; xalign: 0;
label: bind $song_album (template.playbin as <$Playbin>.song) as <string>; label: bind $song_album (template.song) as <string>;
ellipsize: end; ellipsize: end;
} }
} }

View file

@ -20,6 +20,8 @@ class Ui.Window : Adw.ApplicationWindow {
set { this.playbin.mute = value; } set { this.playbin.mute = value; }
} }
public Subsonic.Song? song { get; private set; }
private Cancellable cancel_loading_art; private Cancellable cancel_loading_art;
public bool cover_art_loading { get; set; default = false; } public bool cover_art_loading { get; set; default = false; }
public Gdk.Paintable playing_cover_art { get; set; } public Gdk.Paintable playing_cover_art { get; set; }
@ -54,8 +56,9 @@ class Ui.Window : Adw.ApplicationWindow {
this.api = api; this.api = api;
this.playbin.api = api; this.playbin.api = api;
this.playbin.now_playing.connect (() => { this.playbin.now_playing.connect ((playbin, now, next) => {
api.scrobble.begin (playbin.song.id); this.song = now;
api.scrobble.begin (this.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) { if (this.cancel_loading_art != null) {
@ -64,10 +67,10 @@ class Ui.Window : Adw.ApplicationWindow {
this.cancel_loading_art = new GLib.Cancellable (); this.cancel_loading_art = new GLib.Cancellable ();
this.playing_cover_art = Gdk.Paintable.empty (1, 1); this.playing_cover_art = Gdk.Paintable.empty (1, 1);
if (playbin.song != null) { if (this.song != null) {
this.cover_art_loading = true; this.cover_art_loading = true;
string song_id = playbin.song.id; string song_id = this.song.id;
this.api.cover_art.begin (song_id, this.cancel_loading_art, (obj, res) => { this.api.cover_art.begin (song_id, this.cancel_loading_art, (obj, res) => {
try { try {
this.playing_cover_art = Gdk.Texture.for_pixbuf (this.api.cover_art.end (res)); this.playing_cover_art = Gdk.Texture.for_pixbuf (this.api.cover_art.end (res));