who knows

This commit is contained in:
me 2024-10-13 17:00:47 +00:00
parent cce049c814
commit 45b3444f98
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)";
}
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);

View file

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

View file

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

View file

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