this should be better than inc_position

This commit is contained in:
Erica Z 2024-10-20 13:32:15 +02:00
parent 5c24cde637
commit 26449b9dcf

View file

@ -43,9 +43,6 @@ public class Playbin : GLib.Object {
// signalled when the last track is over
public signal void stopped ();
// set to false when manually switching tracks
private bool inc_position;
// these are mostly synced with mpv
public double position { get; private set; default = 0.0; }
public double duration { get; private set; default = 0.0; }
@ -143,11 +140,6 @@ public class Playbin : GLib.Object {
case Mpv.EventId.START_FILE:
debug ("START_FILE received");
if (this.inc_position) {
this.play_queue_position += 1;
} else {
this.inc_position = true;
}
// estimate duration from api data
// while mpv doesn't know it
@ -157,17 +149,22 @@ public class Playbin : GLib.Object {
break;
case Mpv.EventId.END_FILE:
debug ("END_FILE received");
var data = event.parse_end_file ();
debug (@"END_FILE received (reason: $(data.reason))");
if (data.error < 0) {
warning ("playback of track aborted: %s", data.error.to_string ());
}
if (this.inc_position && this.play_queue_position+1 == this._play_queue.get_n_items ()) {
// reached the end (?)
if (data.reason == Mpv.EndFileReason.EOF) {
// assume this is a proper transition
this.play_queue_position += 1;
this.state = PlaybinState.STOPPED;
this.stopped ();
if (this.play_queue_position == this._play_queue.get_n_items ()) {
// reached the end (?)
this.state = PlaybinState.STOPPED;
this.stopped ();
}
}
break;
@ -196,7 +193,6 @@ public class Playbin : GLib.Object {
assert (this.mpv.command ({"playlist-play-index", position.to_string ()}) >= 0);
this.state = PlaybinState.PLAYING;
this.play_queue_position = position;
this.inc_position = false;
}
public void pause () {
@ -224,7 +220,6 @@ public class Playbin : GLib.Object {
requires (this.state != PlaybinState.STOPPED)
{
if (this.play_queue_position+1 < this._play_queue.get_n_items ()) {
this.inc_position = false;
this.play_queue_position += 1;
assert (this.mpv.command ({"playlist-next-playlist"}) >= 0);
} else {
@ -236,7 +231,6 @@ public class Playbin : GLib.Object {
requires (this.state != PlaybinState.STOPPED)
{
if (this.play_queue_position > 0) {
this.inc_position = false;
this.play_queue_position -= 1;
assert (this.mpv.command ({"playlist-prev-playlist"}) >= 0);
} else {