From 6c12828e3108a3722fbd0bb10563fd277154c3af Mon Sep 17 00:00:00 2001 From: Erica Z Date: Wed, 16 Oct 2024 12:03:32 +0200 Subject: [PATCH] try improve track choosing ux --- src/playbin.vala | 15 ++++++++++++--- src/ui/window.blp | 4 ++-- src/ui/window.vala | 6 ++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/playbin.vala b/src/playbin.vala index d1e74c9..f6e0804 100644 --- a/src/playbin.vala +++ b/src/playbin.vala @@ -28,12 +28,13 @@ class Playbin : GLib.Object { // 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 public Subsonic api { get; set; default = null; } // sent when a new song starts playing // continues: whether the track is a gapless continuation - public signal void now_playing (bool continues, uint index, Song song, int64 duration); + public signal void now_playing (bool continues, uint index, Song song); // the index of the track in the play queue that is currently playing // must equal play queue len iff state is STOPPED @@ -165,6 +166,7 @@ class Playbin : GLib.Object { bus.message["stream-start"].connect ((message) => { int64 duration; assert (this.playbin.query_duration (Gst.Format.TIME, out duration)); + this.duration = duration; this.position = 0; @@ -178,7 +180,9 @@ class Playbin : GLib.Object { var now_playing = (Song) play_queue.get_item (this.current_position); if (this.api.stream_uri (now_playing.id) == (string) this.playbin.current_uri) { - this.now_playing (continues, this.current_position, now_playing, duration); + if (continues) { + this.now_playing (true, this.current_position, now_playing); + } if (this.current_position+1 < play_queue.get_n_items ()) { Song song = (Song) play_queue.get_item (this.current_position+1); @@ -221,7 +225,8 @@ class Playbin : GLib.Object { this.current_position = position; this.playbin.set_state (Gst.State.READY); - this.playbin.uri = this.api.stream_uri (((Song) this.play_queue.get_item (position)).id); + var song = (Song) this.play_queue.get_item (position); + this.playbin.uri = this.api.stream_uri (song.id); this.playbin.set_state (Gst.State.PLAYING); this.next_gapless = false; @@ -230,6 +235,10 @@ class Playbin : GLib.Object { // if it was already empty then uhhhh if theres any problems then // playbin.uri wont match up with the current track's stream uri and we can // fix it there + + this.now_playing (false, position, song); + this.position = 0; + this.duration = 1; } public void pause () { diff --git a/src/ui/window.blp b/src/ui/window.blp index 06b3bfb..486f1c6 100644 --- a/src/ui/window.blp +++ b/src/ui/window.blp @@ -148,7 +148,7 @@ template $UiWindow: Adw.ApplicationWindow { adjustment: Adjustment { lower: 0; value: bind template.position; - upper: bind template.duration; + upper: bind template.playbin as <$Playbin>.duration; }; change-value => $on_play_position_seek (); @@ -161,7 +161,7 @@ template $UiWindow: Adw.ApplicationWindow { "numeric", ] - label: bind $format_timestamp (template.duration) as ; + label: bind $format_timestamp (template.playbin as <$Playbin>.duration) as ; } } diff --git a/src/ui/window.vala b/src/ui/window.vala index d44e824..d8a1950 100644 --- a/src/ui/window.vala +++ b/src/ui/window.vala @@ -10,7 +10,6 @@ class Ui.Window : Adw.ApplicationWindow { private Setup setup; public int64 position { get; private set; } - public int64 duration { get; private set; } public double volume { get { return this.playbin.volume; } @@ -61,9 +60,8 @@ class Ui.Window : Adw.ApplicationWindow { this.setup.connected.connect ((api) => { this.playbin.api = api; - this.playbin.now_playing.connect ((continues, position, song, duration) => { + this.playbin.now_playing.connect ((continues, position, song) => { this.song = song; - this.duration = duration; api.scrobble.begin (song.id); this.play_queue.selection.playbin_select (position); }); @@ -214,7 +212,7 @@ class Ui.Window : Adw.ApplicationWindow { [GtkCallback] private void seek_forward () { // 10 seconds int64 new_position = position + (int64)10 * 1000 * 1000000; - if (new_position > this.duration) new_position = this.duration; + if (new_position > this.playbin.duration) new_position = this.playbin.duration; this.seek_impl (new_position); } }