From df3484f14720c7c68e7490dc248c0c6c519f7f78 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Fri, 18 Oct 2024 22:27:24 +0200 Subject: [PATCH] better event tracking --- src/playbin.vala | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/playbin.vala b/src/playbin.vala index fd6a177..50cb31a 100644 --- a/src/playbin.vala +++ b/src/playbin.vala @@ -115,10 +115,15 @@ class Playbin : GLib.Object { case 2: assert (data.name == "playlist-pos"); if (data.format == Mpv.Format.NONE) { - this.play_queue_position = 0; + this.play_queue_position = this.play_queue.get_n_items (); } else { - this.play_queue_position = (uint) data.parse_int64 (); + if (data.parse_int64 () < 0) { + this.play_queue_position = this.play_queue.get_n_items (); + } else { + this.play_queue_position = (uint) data.parse_int64 (); + } } + debug (@"playlist-pos has been updated to $(this.play_queue_position)"); break; default: @@ -127,17 +132,16 @@ class Playbin : GLib.Object { } break; - case Mpv.EventId.FILE_LOADED: - if (this.notify_next_playing) { + case Mpv.EventId.START_FILE: + debug ("START_FILE received"); + if (this.play_queue_position < this.play_queue.get_n_items ()) { this.song = (Subsonic.Song) this.play_queue.get_item (this.play_queue_position); this.now_playing (); - } else { - assert (this.song == (Subsonic.Song) this.play_queue.get_item (this.play_queue_position)); - this.notify_next_playing = true; } break; case Mpv.EventId.END_FILE: + debug ("END_FILE received"); var data = event.parse_end_file (); if (data.error < 0) { warning ("playback of track aborted: %s", data.error.to_string ());