From 854d2422fd681f2dee144a7f3df93b36cf33c913 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Sun, 13 Oct 2024 17:00:47 +0000 Subject: [PATCH] who knows --- src/api.vala | 8 ++++---- src/playbin.vala | 36 ++++++++++++++++++++++++++---------- src/ui/window.blp | 20 +++++++++++++------- src/ui/window.vala | 10 ++++------ 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/api.vala b/src/api.vala index a49d670..a8a824c 100644 --- a/src/api.vala +++ b/src/api.vala @@ -239,12 +239,12 @@ public class Subsonic : Object { return @"$(this.url)/rest/stream?id=$(Uri.escape_string(id))&$(this.parameters)"; } - public string cover_art_uri (string id, int size) { - return @"$(this.url)/rest/getCoverArt?id=$(Uri.escape_string(id))&$(size)&$(this.parameters)"; + public string cover_art_uri (string id) { + return @"$(this.url)/rest/getCoverArt?id=$(Uri.escape_string(id))&$(this.parameters)"; } - public async Gdk.Pixbuf cover_art (string id, int size, Cancellable cancellable) throws Error { - var msg = new Soup.Message("GET", this.cover_art_uri (id, size)); + public async Gdk.Pixbuf cover_art (string id, Cancellable cancellable) throws Error { + var msg = new Soup.Message("GET", this.cover_art_uri (id)); assert (msg != null); var stream = yield this.session.send_async (msg, Priority.DEFAULT, cancellable); diff --git a/src/playbin.vala b/src/playbin.vala index d664e70..1435b0f 100644 --- a/src/playbin.vala +++ b/src/playbin.vala @@ -26,6 +26,8 @@ class Playbin : Object { public PlaybinState state { get; private set; default = PlaybinState.STOPPED; } + private bool update_position = false; + public int64 position { get; private set; } public int64 duration { get; private set; } @@ -45,13 +47,15 @@ class Playbin : Object { this.playbin.source_setup.connect (this.source_setup); this.playbin.about_to_finish.connect (this.about_to_finish); - // regularly update position + // regularly update position/duration Timeout.add (500, () => { - 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; + if (this.update_position) { + 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 @@ -76,6 +80,15 @@ class Playbin : Object { }); bus.message["stream-start"].connect ((message) => { + int64 new_duration; + if (this.playbin.query_duration (Gst.Format.TIME, out new_duration)) { + this.duration = new_duration; + } else { + warning ("could not obtain new stream duration"); + } + + this.position = 0; + if (notify_next_transition) { this.song_transition ((string) this.playbin.current_uri); } else { @@ -83,10 +96,13 @@ class Playbin : Object { } }); - bus.message["async-done"].connect ((message) => { - int64 new_duration; - assert (this.playbin.query_duration (Gst.Format.TIME, out new_duration)); - this.duration = new_duration; + bus.message["state-changed"].connect ((message) => { + if (message.src != this.playbin) return; + + Gst.State new_state; + message.parse_state_changed (null, out new_state, null); + + this.update_position = new_state == Gst.State.PLAYING; }); bus.message["eos"].connect ((message) => { diff --git a/src/ui/window.blp b/src/ui/window.blp index a835f55..88cb89e 100644 --- a/src/ui/window.blp +++ b/src/ui/window.blp @@ -99,18 +99,24 @@ template $UiWindow: Adw.ApplicationWindow { Label { styles [ "heading" ] + xalign: 0; halign: start; label: bind template.song as <$Song>.title; ellipsize: end; } - Box { - halign: start; - Label { - styles [ "caption" ] - label: bind $format_song_below_title (template.song) as ; - ellipsize: end; - } + Label { + styles [ "caption" ] + xalign: 0; + label: bind template.song as <$Song>.artist; + ellipsize: end; + } + + Label { + styles [ "caption" ] + xalign: 0; + label: bind template.song as <$Song>.album; + ellipsize: end; } } diff --git a/src/ui/window.vala b/src/ui/window.vala index 82b1c86..5ecd20e 100644 --- a/src/ui/window.vala +++ b/src/ui/window.vala @@ -26,6 +26,8 @@ class Ui.Window : Adw.ApplicationWindow { public bool cover_art_loading { get; set; default = false; } public Gdk.Paintable playing_cover_art { get; set; } + private Gdk.Paintable next_cover_art = null; + internal Playbin playbin { get; default = new Playbin (); } public Window (Gtk.Application app) { @@ -122,12 +124,12 @@ class Ui.Window : Adw.ApplicationWindow { } this.cancel_loading_art = new Cancellable (); - this.playing_cover_art = Gdk.Paintable.empty (100, 100); + this.playing_cover_art = Gdk.Paintable.empty (1, 1); if (this.song != null) { this.cover_art_loading = true; string song_id = this.song.id; - public_api.cover_art.begin (song_id, 100, this.cancel_loading_art, (obj, res) => { + public_api.cover_art.begin (song_id, this.cancel_loading_art, (obj, res) => { try { this.playing_cover_art = Gdk.Texture.for_pixbuf (public_api.cover_art.end (res)); this.cover_art_loading = false; @@ -220,10 +222,6 @@ class Ui.Window : Adw.ApplicationWindow { this.setup.present (this); } - [GtkCallback] private string format_song_below_title (Song? song) { - return song == null ? "" : @"$(song.artist) - $(song.album) - $(song.year)"; - } - [GtkCallback] private void seek_backward () { // 10 seconds int64 new_position = position - (int64)10 * 1000 * 1000000;