mirror of
https://gitlab.com/liyaowhen/youtubecollector-git.git
synced 2026-10-01 01:12:59 +00:00
seek bar works, but big bug
This commit is contained in:
@@ -15,7 +15,7 @@ namespace Song {
|
||||
|
||||
public static SongControls song_controls;
|
||||
|
||||
public static GestureDrag gesture;
|
||||
public static Adw.ApplicationWindow window;
|
||||
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ song_deps = [
|
||||
dependency('libadwaita-1', version: '>= 1.4'),
|
||||
dependency('vte-2.91-gtk4'),
|
||||
dependency('jsonrpc-glib-1.0'),
|
||||
dependency('gstreamer-1.0')
|
||||
dependency('gstreamer-1.0'),
|
||||
]
|
||||
|
||||
song_sources += gnome.compile_resources('song-resources',
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Song {
|
||||
public Gtk.Scale progress_bar;
|
||||
public Gtk.Adjustment progress_bar_adjustment;
|
||||
private bool isDragging;
|
||||
private Gtk.Button progress_bar_controller;
|
||||
|
||||
public bool isPlaying;
|
||||
public string current_song;
|
||||
@@ -35,55 +36,45 @@ namespace Song {
|
||||
progress_bar.set_draw_value(false);
|
||||
|
||||
|
||||
Timeout.add(1, () => {
|
||||
Timeout.add(500, () => {
|
||||
|
||||
if (playbin != null && isDragging != true) {
|
||||
if (playbin != null && isPlaying) {
|
||||
var position = (int64) 0;
|
||||
var duration = (int64) 0;
|
||||
|
||||
playbin.set_state(Gst.State.PLAYING);
|
||||
|
||||
// Query the current position and duration
|
||||
if (playbin.query_position(Format.TIME, out position) &&
|
||||
playbin.query_duration(Format.TIME, out duration)) {
|
||||
progress_bar.set_range(0, (double) duration / Gst.SECOND);
|
||||
progress_bar.set_value((double) position / Gst.SECOND);
|
||||
}
|
||||
print(position.to_string() + "\n" + duration.to_string() + "\n");
|
||||
} else {
|
||||
if (isDragging) print("stillDragging");
|
||||
if (playbin == null) print("playbinnull");
|
||||
print("what went wrong");
|
||||
}
|
||||
//print("running");
|
||||
|
||||
print("working");
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
uint timeout_id = 0;
|
||||
|
||||
progress_bar.change_value.connect((range) => {
|
||||
|
||||
if (timeout_id != 0) {
|
||||
try {
|
||||
Source.remove(timeout_id);
|
||||
} catch (GLib.Error e) {
|
||||
// the function above often complains
|
||||
}
|
||||
}
|
||||
|
||||
isDragging = true;
|
||||
if (playbin != null) {
|
||||
var seek_time = (int64)(progress_bar.get_value() * Gst.SECOND);
|
||||
playbin.seek_simple(Format.TIME, SeekFlags.FLUSH | SeekFlags.KEY_UNIT, seek_time);
|
||||
}
|
||||
|
||||
timeout_id = Timeout.add(50, () => {
|
||||
|
||||
isDragging = false;
|
||||
|
||||
return false;
|
||||
});
|
||||
}); // emitted when user (not program) changes the scale
|
||||
|
||||
progress_bar.value_changed.connect((range) => {
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
append(progress_bar);
|
||||
|
||||
// add controls to control the music
|
||||
@@ -112,6 +103,7 @@ namespace Song {
|
||||
play_button.set_icon_name("media-playback-start-symbolic");
|
||||
}
|
||||
return true;
|
||||
|
||||
});
|
||||
|
||||
play_button.clicked.connect(() => {
|
||||
|
||||
+1
-3
@@ -12,7 +12,7 @@ namespace Song {
|
||||
|
||||
construct {
|
||||
|
||||
var gesture = new Gtk.GestureDrag();
|
||||
SongController.window = this;
|
||||
|
||||
var provider = new Gtk.CssProvider();
|
||||
provider.load_from_path("style.css");
|
||||
@@ -58,8 +58,6 @@ namespace Song {
|
||||
_content.add_top_bar (title_bar);
|
||||
_content.set_content (split_view);
|
||||
|
||||
_content.add_controller(gesture);
|
||||
SongController.gesture = gesture;
|
||||
|
||||
collapse_button.clicked.connect(() => {
|
||||
if(split_view.get_collapsed ()){
|
||||
|
||||
Reference in New Issue
Block a user