instantly update next track info when manually switching

This commit is contained in:
Erica Z 2024-10-18 22:17:04 +02:00
parent 72c8507126
commit 0f1bbec5de

View file

@ -37,6 +37,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; } public Subsonic.Song? song { get; private set; }
private bool notify_next_playing;
public signal void now_playing (); public signal void now_playing ();
public double position { get; private set; default = 0.0; } public double position { get; private set; default = 0.0; }
@ -126,8 +128,13 @@ class Playbin : GLib.Object {
break; break;
case Mpv.EventId.FILE_LOADED: case Mpv.EventId.FILE_LOADED:
if (this.notify_next_playing) {
this.song = (Subsonic.Song) this.play_queue.get_item (this.play_queue_position); this.song = (Subsonic.Song) this.play_queue.get_item (this.play_queue_position);
this.now_playing (); this.now_playing ();
} else {
assert (this.song == (Subsonic.Song) this.play_queue.get_item (this.play_queue_position));
this.notify_next_playing = true;
}
break; break;
case Mpv.EventId.END_FILE: case Mpv.EventId.END_FILE:
@ -159,6 +166,10 @@ 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 () {