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
|
// lets us access the about-to-finish signal
|
||||||
private dynamic Gst.Element playbin = Gst.ElementFactory.make ("playbin3", null);
|
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?
|
// cubic: recommended for media player volume sliders?
|
||||||
public double volume {
|
public double volume {
|
||||||
get {
|
get {
|
||||||
|
@ -29,7 +26,6 @@ class Playbin : Object {
|
||||||
|
|
||||||
public PlaybinState state { get; private set; default = PlaybinState.STOPPED; }
|
public PlaybinState state { get; private set; default = PlaybinState.STOPPED; }
|
||||||
|
|
||||||
private bool seeking = false;
|
|
||||||
public int64 position { get; private set; }
|
public int64 position { get; private set; }
|
||||||
public int64 duration { get; private set; }
|
public int64 duration { get; private set; }
|
||||||
|
|
||||||
|
@ -51,14 +47,12 @@ class Playbin : Object {
|
||||||
|
|
||||||
// regularly update position
|
// regularly update position
|
||||||
Timeout.add (500, () => {
|
Timeout.add (500, () => {
|
||||||
if (!this.seeking) {
|
|
||||||
int64 new_position;
|
int64 new_position;
|
||||||
if (this.playbin.query_position (Gst.Format.TIME, out new_position)) {
|
if (this.playbin.query_position (Gst.Format.TIME, out new_position)) {
|
||||||
this.position = new_position < this.duration ? new_position : this.duration;
|
this.position = new_position < this.duration ? new_position : this.duration;
|
||||||
} else {
|
} else {
|
||||||
this.position = 0;
|
this.position = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// keep rerunning
|
// keep rerunning
|
||||||
return true;
|
return true;
|
||||||
|
@ -81,26 +75,7 @@ class Playbin : Object {
|
||||||
warning ("gst playbin bus warning: %s", err.message);
|
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) => {
|
bus.message["stream-start"].connect ((message) => {
|
||||||
this.stream_counter += 1;
|
|
||||||
|
|
||||||
if (notify_next_transition) {
|
if (notify_next_transition) {
|
||||||
this.song_transition ((string) this.playbin.current_uri);
|
this.song_transition ((string) this.playbin.current_uri);
|
||||||
} else {
|
} else {
|
||||||
|
@ -120,19 +95,9 @@ class Playbin : Object {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private uint64 queued_seek_counter;
|
|
||||||
private int64 queued_seek_position = -1;
|
|
||||||
|
|
||||||
public void seek (int64 position) {
|
public void seek (int64 position) {
|
||||||
if (this.state == PlaybinState.STOPPED) return;
|
if (!this.playbin.seek_simple (Gst.Format.TIME, Gst.SeekFlags.FLUSH, position)) {
|
||||||
|
warning ("could not seek");
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,17 +162,21 @@ class Ui.Window : Adw.ApplicationWindow {
|
||||||
return "%02d:%02d".printf (s/60, s%60);
|
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 void seek_impl (int64 position) {
|
||||||
private uint seek_timeout_id = 0;
|
this.position = position;
|
||||||
[GtkCallback] private bool on_play_position_seek (Gtk.Range range, Gtk.ScrollType scroll_type, double value) {
|
|
||||||
this.position = (int64) range.adjustment.value;
|
|
||||||
if (this.seek_timeout_id == 0) {
|
if (this.seek_timeout_id == 0) {
|
||||||
this.seek_timeout_id = Timeout.add (500, () => {
|
this.seek_timeout_id = Timeout.add (500, () => {
|
||||||
playbin.seek((int64) range.adjustment.value);
|
playbin.seek(this.position);
|
||||||
this.seek_timeout_id = 0;
|
this.seek_timeout_id = 0;
|
||||||
return false;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,15 +228,13 @@ class Ui.Window : Adw.ApplicationWindow {
|
||||||
// 10 seconds
|
// 10 seconds
|
||||||
int64 new_position = position - (int64)10 * 1000 * 1000000;
|
int64 new_position = position - (int64)10 * 1000 * 1000000;
|
||||||
if (new_position < 0) new_position = 0;
|
if (new_position < 0) new_position = 0;
|
||||||
this.position = new_position;
|
this.seek_impl (new_position);
|
||||||
this.playbin.seek (new_position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[GtkCallback] private void seek_forward () {
|
[GtkCallback] private void seek_forward () {
|
||||||
// 10 seconds
|
// 10 seconds
|
||||||
int64 new_position = position + (int64)10 * 1000 * 1000000;
|
int64 new_position = position + (int64)10 * 1000 * 1000000;
|
||||||
if (new_position > this.playbin.duration) new_position = this.playbin.duration;
|
if (new_position > this.playbin.duration) new_position = this.playbin.duration;
|
||||||
this.position = new_position;
|
this.seek_impl (new_position);
|
||||||
this.playbin.seek (new_position);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue