attempt to unfuck seeking
This commit is contained in:
parent
7268b1bacf
commit
8b4450c10f
2 changed files with 19 additions and 52 deletions
|
@ -9,9 +9,6 @@ class Playbin : Object {
|
|||
// lets us access the about-to-finish signal
|
||||
private dynamic Gst.Element playbin = Gst.ElementFactory.make ("playbin3", null);
|
||||
|
||||
// used to prevent stale seeks
|
||||
private uint64 stream_counter = 0;
|
||||
|
||||
// cubic: recommended for media player volume sliders?
|
||||
public double volume {
|
||||
get {
|
||||
|
@ -29,7 +26,6 @@ class Playbin : Object {
|
|||
|
||||
public PlaybinState state { get; private set; default = PlaybinState.STOPPED; }
|
||||
|
||||
private bool seeking = false;
|
||||
public int64 position { get; private set; }
|
||||
public int64 duration { get; private set; }
|
||||
|
||||
|
@ -51,13 +47,11 @@ class Playbin : Object {
|
|||
|
||||
// regularly update position
|
||||
Timeout.add (500, () => {
|
||||
if (!this.seeking) {
|
||||
int64 new_position;
|
||||
if (this.playbin.query_position (Gst.Format.TIME, out new_position)) {
|
||||
this.position = new_position < this.duration ? new_position : this.duration;
|
||||
} else {
|
||||
this.position = 0;
|
||||
}
|
||||
int64 new_position;
|
||||
if (this.playbin.query_position (Gst.Format.TIME, out new_position)) {
|
||||
this.position = new_position < this.duration ? new_position : this.duration;
|
||||
} else {
|
||||
this.position = 0;
|
||||
}
|
||||
|
||||
// keep rerunning
|
||||
|
@ -81,26 +75,7 @@ class Playbin : Object {
|
|||
warning ("gst playbin bus warning: %s", err.message);
|
||||
});
|
||||
|
||||
bus.message["state-changed"].connect ((message) => {
|
||||
if (message.src != this.playbin) return;
|
||||
|
||||
Gst.State old_state;
|
||||
Gst.State new_state;
|
||||
message.parse_state_changed (out old_state, out new_state, null);
|
||||
|
||||
if (new_state == Gst.State.PLAYING) {
|
||||
if (this.queued_seek_position < 0) {
|
||||
this.seeking = false;
|
||||
} else if (this.queued_seek_counter == this.stream_counter) {
|
||||
assert (this.playbin.seek_simple (Gst.Format.TIME, Gst.SeekFlags.FLUSH, this.queued_seek_position));
|
||||
}
|
||||
this.queued_seek_position = -1;
|
||||
}
|
||||
});
|
||||
|
||||
bus.message["stream-start"].connect ((message) => {
|
||||
this.stream_counter += 1;
|
||||
|
||||
if (notify_next_transition) {
|
||||
this.song_transition ((string) this.playbin.current_uri);
|
||||
} else {
|
||||
|
@ -120,19 +95,9 @@ class Playbin : Object {
|
|||
});
|
||||
}
|
||||
|
||||
private uint64 queued_seek_counter;
|
||||
private int64 queued_seek_position = -1;
|
||||
|
||||
public void seek (int64 position) {
|
||||
if (this.state == PlaybinState.STOPPED) return;
|
||||
|
||||
if (this.playbin.seek_simple (Gst.Format.TIME, Gst.SeekFlags.FLUSH, position)) {
|
||||
this.seeking = true;
|
||||
this.position = position;
|
||||
} else {
|
||||
// queue this seek
|
||||
this.queued_seek_counter = this.stream_counter;
|
||||
this.queued_seek_position = position;
|
||||
if (!this.playbin.seek_simple (Gst.Format.TIME, Gst.SeekFlags.FLUSH, position)) {
|
||||
warning ("could not seek");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -162,17 +162,21 @@ class Ui.Window : Adw.ApplicationWindow {
|
|||
return "%02d:%02d".printf (s/60, s%60);
|
||||
}
|
||||
|
||||
// same timeout logic as https://code.videolan.org/videolan/npapi-vlc/blob/6eae0ffb9cbaf8f6e04423de2ff38daabdf7cae3/npapi/vlcplugin_gtk.cpp#L312
|
||||
private uint seek_timeout_id = 0;
|
||||
[GtkCallback] private bool on_play_position_seek (Gtk.Range range, Gtk.ScrollType scroll_type, double value) {
|
||||
this.position = (int64) range.adjustment.value;
|
||||
private void seek_impl (int64 position) {
|
||||
this.position = position;
|
||||
if (this.seek_timeout_id == 0) {
|
||||
this.seek_timeout_id = Timeout.add (500, () => {
|
||||
playbin.seek((int64) range.adjustment.value);
|
||||
playbin.seek(this.position);
|
||||
this.seek_timeout_id = 0;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// same timeout logic as https://code.videolan.org/videolan/npapi-vlc/blob/6eae0ffb9cbaf8f6e04423de2ff38daabdf7cae3/npapi/vlcplugin_gtk.cpp#L312
|
||||
private uint seek_timeout_id = 0;
|
||||
[GtkCallback] private bool on_play_position_seek (Gtk.Range range, Gtk.ScrollType scroll_type, double value) {
|
||||
this.seek_impl((int64) value);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -224,15 +228,13 @@ class Ui.Window : Adw.ApplicationWindow {
|
|||
// 10 seconds
|
||||
int64 new_position = position - (int64)10 * 1000 * 1000000;
|
||||
if (new_position < 0) new_position = 0;
|
||||
this.position = new_position;
|
||||
this.playbin.seek (new_position);
|
||||
this.seek_impl (new_position);
|
||||
}
|
||||
|
||||
[GtkCallback] private void seek_forward () {
|
||||
// 10 seconds
|
||||
int64 new_position = position + (int64)10 * 1000 * 1000000;
|
||||
if (new_position > this.playbin.duration) new_position = this.playbin.duration;
|
||||
this.position = new_position;
|
||||
this.playbin.seek (new_position);
|
||||
this.seek_impl (new_position);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue