who knows

This commit is contained in:
Erica Z 2024-10-13 17:00:47 +00:00
parent 8b4450c10f
commit 814aa93bf0
4 changed files with 47 additions and 27 deletions

View file

@ -239,12 +239,12 @@ public class Subsonic : Object {
return @"$(this.url)/rest/stream?id=$(Uri.escape_string(id))&$(this.parameters)"; return @"$(this.url)/rest/stream?id=$(Uri.escape_string(id))&$(this.parameters)";
} }
public string cover_art_uri (string id, int size) { public string cover_art_uri (string id) {
return @"$(this.url)/rest/getCoverArt?id=$(Uri.escape_string(id))&$(size)&$(this.parameters)"; 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 { public async Gdk.Pixbuf cover_art (string id, Cancellable cancellable) throws Error {
var msg = new Soup.Message("GET", this.cover_art_uri (id, size)); var msg = new Soup.Message("GET", this.cover_art_uri (id));
assert (msg != null); assert (msg != null);
var stream = yield this.session.send_async (msg, Priority.DEFAULT, cancellable); var stream = yield this.session.send_async (msg, Priority.DEFAULT, cancellable);

View file

@ -26,6 +26,8 @@ class Playbin : Object {
public PlaybinState state { get; private set; default = PlaybinState.STOPPED; } public PlaybinState state { get; private set; default = PlaybinState.STOPPED; }
private bool update_position = 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; }
@ -45,13 +47,15 @@ class Playbin : Object {
this.playbin.source_setup.connect (this.source_setup); this.playbin.source_setup.connect (this.source_setup);
this.playbin.about_to_finish.connect (this.about_to_finish); this.playbin.about_to_finish.connect (this.about_to_finish);
// regularly update position // regularly update position/duration
Timeout.add (500, () => { Timeout.add (500, () => {
int64 new_position; if (this.update_position) {
if (this.playbin.query_position (Gst.Format.TIME, out new_position)) { int64 new_position;
this.position = new_position < this.duration ? new_position : this.duration; if (this.playbin.query_position (Gst.Format.TIME, out new_position)) {
} else { this.position = new_position < this.duration ? new_position : this.duration;
this.position = 0; } else {
this.position = 0;
}
} }
// keep rerunning // keep rerunning
@ -76,6 +80,15 @@ class Playbin : Object {
}); });
bus.message["stream-start"].connect ((message) => { 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) { if (notify_next_transition) {
this.song_transition ((string) this.playbin.current_uri); this.song_transition ((string) this.playbin.current_uri);
} else { } else {
@ -83,10 +96,13 @@ class Playbin : Object {
} }
}); });
bus.message["async-done"].connect ((message) => { bus.message["state-changed"].connect ((message) => {
int64 new_duration; if (message.src != this.playbin) return;
assert (this.playbin.query_duration (Gst.Format.TIME, out new_duration));
this.duration = new_duration; 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) => { bus.message["eos"].connect ((message) => {

View file

@ -99,18 +99,24 @@ template $UiWindow: Adw.ApplicationWindow {
Label { Label {
styles [ "heading" ] styles [ "heading" ]
xalign: 0;
halign: start; halign: start;
label: bind template.song as <$Song>.title; label: bind template.song as <$Song>.title;
ellipsize: end; ellipsize: end;
} }
Box { Label {
halign: start; styles [ "caption" ]
Label { xalign: 0;
styles [ "caption" ] label: bind template.song as <$Song>.artist;
label: bind $format_song_below_title (template.song) as <string>; ellipsize: end;
ellipsize: end; }
}
Label {
styles [ "caption" ]
xalign: 0;
label: bind template.song as <$Song>.album;
ellipsize: end;
} }
} }

View file

@ -26,6 +26,8 @@ class Ui.Window : Adw.ApplicationWindow {
public bool cover_art_loading { get; set; default = false; } public bool cover_art_loading { get; set; default = false; }
public Gdk.Paintable playing_cover_art { get; set; } public Gdk.Paintable playing_cover_art { get; set; }
private Gdk.Paintable next_cover_art = null;
internal Playbin playbin { get; default = new Playbin (); } internal Playbin playbin { get; default = new Playbin (); }
public Window (Gtk.Application app) { public Window (Gtk.Application app) {
@ -122,12 +124,12 @@ class Ui.Window : Adw.ApplicationWindow {
} }
this.cancel_loading_art = new Cancellable (); 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) { if (this.song != null) {
this.cover_art_loading = true; this.cover_art_loading = true;
string song_id = this.song.id; 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 { try {
this.playing_cover_art = Gdk.Texture.for_pixbuf (public_api.cover_art.end (res)); this.playing_cover_art = Gdk.Texture.for_pixbuf (public_api.cover_art.end (res));
this.cover_art_loading = false; this.cover_art_loading = false;
@ -220,10 +222,6 @@ class Ui.Window : Adw.ApplicationWindow {
this.setup.present (this); 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 () { [GtkCallback] private void seek_backward () {
// 10 seconds // 10 seconds
int64 new_position = position - (int64)10 * 1000 * 1000000; int64 new_position = position - (int64)10 * 1000 * 1000000;