try improve track choosing ux

This commit is contained in:
Erica Z 2024-10-16 12:03:32 +02:00
parent 636774d787
commit 6c12828e31
3 changed files with 16 additions and 9 deletions

View file

@ -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 () {

View file

@ -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 <string>;
label: bind $format_timestamp (template.playbin as <$Playbin>.duration) as <string>;
}
}

View file

@ -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);
}
}