try new seeking
This commit is contained in:
parent
2fe276bfbd
commit
c4dbba35c0
1 changed files with 14 additions and 27 deletions
|
@ -27,8 +27,6 @@ class Playbin : GLib.Object {
|
|||
|
||||
public Subsonic.Song? current_song { get; private set; default = null; }
|
||||
|
||||
// true if a timer should update the position property
|
||||
private bool update_position = false;
|
||||
public int64 position { get; private set; default = 0; }
|
||||
public int64 duration { get; private set; default = 1; } // if 0, the seekbar vanishes
|
||||
|
||||
|
@ -122,6 +120,8 @@ class Playbin : GLib.Object {
|
|||
}
|
||||
}
|
||||
|
||||
private bool queued_seek = false;
|
||||
|
||||
public Playbin () {
|
||||
this.next_uri.push ("");
|
||||
|
||||
|
@ -129,14 +129,16 @@ class Playbin : GLib.Object {
|
|||
this.playbin.about_to_finish.connect (this.about_to_finish);
|
||||
|
||||
// regularly update position
|
||||
Timeout.add (500, () => {
|
||||
if (this.update_position) {
|
||||
Timeout.add (100, () => {
|
||||
if (this.queued_seek) {
|
||||
if (this.playbin.seek_simple (Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE, position)) {
|
||||
this.queued_seek = false;
|
||||
}
|
||||
} else {
|
||||
int64 new_position;
|
||||
if (this.playbin.query_position (Gst.Format.TIME, out new_position)) {
|
||||
if (new_position > this.duration) this.position = this.duration;
|
||||
else this.position = new_position;
|
||||
} else {
|
||||
this.position = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,9 +169,7 @@ class Playbin : GLib.Object {
|
|||
this.duration = duration;
|
||||
|
||||
// cancel any queued seeks
|
||||
this.queued_seek = -1;
|
||||
this.update_position = true;
|
||||
|
||||
this.queued_seek = false;
|
||||
this.position = 0;
|
||||
|
||||
bool continues = this.next_gapless;
|
||||
|
@ -205,18 +205,6 @@ class Playbin : GLib.Object {
|
|||
|
||||
Gst.State new_state;
|
||||
message.parse_state_changed (null, out new_state, null);
|
||||
|
||||
if (new_state == Gst.State.PLAYING) {
|
||||
if (queued_seek != -1) {
|
||||
if (this.playbin.seek_simple (Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE, this.queued_seek)) {
|
||||
this.queued_seek = -1;
|
||||
} else {
|
||||
warning ("could not reapply queued seek after state changed changed to playing, retrying later");
|
||||
}
|
||||
} else {
|
||||
this.update_position = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bus.message["eos"].connect ((message) => {
|
||||
|
@ -224,14 +212,13 @@ class Playbin : GLib.Object {
|
|||
});
|
||||
}
|
||||
|
||||
private int64 queued_seek = -1;
|
||||
|
||||
public void seek (int64 position) {
|
||||
this.position = position;
|
||||
this.update_position = false;
|
||||
if (!this.playbin.seek_simple (Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE, position)) {
|
||||
// try to queue this seek for later
|
||||
queued_seek = position;
|
||||
|
||||
if (!this.queued_seek) {
|
||||
if (!this.playbin.seek_simple (Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE, position)) {
|
||||
this.queued_seek = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue