Compare commits
No commits in common. "d2025102e6f93ad0ee6b9075d9843e311b8384fb" and "5c24cde637e31f6c257079c21c9a92ae5254f46a" have entirely different histories.
d2025102e6
...
5c24cde637
1 changed files with 18 additions and 16 deletions
|
@ -43,6 +43,9 @@ public class Playbin : GLib.Object {
|
||||||
// signalled when the last track is over
|
// signalled when the last track is over
|
||||||
public signal void stopped ();
|
public signal void stopped ();
|
||||||
|
|
||||||
|
// set to false when manually switching tracks
|
||||||
|
private bool inc_position;
|
||||||
|
|
||||||
// these are mostly synced with mpv
|
// these are mostly synced with mpv
|
||||||
public double position { get; private set; default = 0.0; }
|
public double position { get; private set; default = 0.0; }
|
||||||
public double duration { get; private set; default = 0.0; }
|
public double duration { get; private set; default = 0.0; }
|
||||||
|
@ -140,6 +143,11 @@ public class Playbin : GLib.Object {
|
||||||
|
|
||||||
case Mpv.EventId.START_FILE:
|
case Mpv.EventId.START_FILE:
|
||||||
debug ("START_FILE received");
|
debug ("START_FILE received");
|
||||||
|
if (this.inc_position) {
|
||||||
|
this.play_queue_position += 1;
|
||||||
|
} else {
|
||||||
|
this.inc_position = true;
|
||||||
|
}
|
||||||
|
|
||||||
// estimate duration from api data
|
// estimate duration from api data
|
||||||
// while mpv doesn't know it
|
// while mpv doesn't know it
|
||||||
|
@ -149,23 +157,18 @@ public class Playbin : GLib.Object {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Mpv.EventId.END_FILE:
|
case Mpv.EventId.END_FILE:
|
||||||
|
debug ("END_FILE received");
|
||||||
var data = event.parse_end_file ();
|
var data = event.parse_end_file ();
|
||||||
debug (@"END_FILE received (reason: $(data.reason))");
|
|
||||||
|
|
||||||
if (data.error < 0) {
|
if (data.error < 0) {
|
||||||
warning ("playback of track aborted: %s", data.error.to_string ());
|
warning ("playback of track aborted: %s", data.error.to_string ());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.reason == Mpv.EndFileReason.EOF) {
|
if (this.inc_position && this.play_queue_position+1 == this._play_queue.get_n_items ()) {
|
||||||
// assume this is a proper transition
|
|
||||||
this.play_queue_position += 1;
|
|
||||||
|
|
||||||
if (this.play_queue_position == this._play_queue.get_n_items ()) {
|
|
||||||
// reached the end (?)
|
// reached the end (?)
|
||||||
|
this.play_queue_position += 1;
|
||||||
this.state = PlaybinState.STOPPED;
|
this.state = PlaybinState.STOPPED;
|
||||||
this.stopped ();
|
this.stopped ();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -182,12 +185,8 @@ public class Playbin : GLib.Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void seek (double position) {
|
public void seek (double position) {
|
||||||
var rc = this.mpv.command ({"seek", position.to_string (), "absolute"});
|
|
||||||
if (rc < 0) {
|
|
||||||
warning (@"could not seek to $position: $rc");
|
|
||||||
} else {
|
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
assert (this.mpv.command ({"seek", position.to_string (), "absolute"}) >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// manually changes which track in the play queue to play
|
// manually changes which track in the play queue to play
|
||||||
|
@ -197,6 +196,7 @@ public 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.play_queue_position = position;
|
||||||
|
this.inc_position = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause () {
|
public void pause () {
|
||||||
|
@ -224,6 +224,7 @@ public class Playbin : GLib.Object {
|
||||||
requires (this.state != PlaybinState.STOPPED)
|
requires (this.state != PlaybinState.STOPPED)
|
||||||
{
|
{
|
||||||
if (this.play_queue_position+1 < this._play_queue.get_n_items ()) {
|
if (this.play_queue_position+1 < this._play_queue.get_n_items ()) {
|
||||||
|
this.inc_position = false;
|
||||||
this.play_queue_position += 1;
|
this.play_queue_position += 1;
|
||||||
assert (this.mpv.command ({"playlist-next-playlist"}) >= 0);
|
assert (this.mpv.command ({"playlist-next-playlist"}) >= 0);
|
||||||
} else {
|
} else {
|
||||||
|
@ -235,6 +236,7 @@ public class Playbin : GLib.Object {
|
||||||
requires (this.state != PlaybinState.STOPPED)
|
requires (this.state != PlaybinState.STOPPED)
|
||||||
{
|
{
|
||||||
if (this.play_queue_position > 0) {
|
if (this.play_queue_position > 0) {
|
||||||
|
this.inc_position = false;
|
||||||
this.play_queue_position -= 1;
|
this.play_queue_position -= 1;
|
||||||
assert (this.mpv.command ({"playlist-prev-playlist"}) >= 0);
|
assert (this.mpv.command ({"playlist-prev-playlist"}) >= 0);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue