propertify current song
This commit is contained in:
parent
dee32826ec
commit
70f9e4f3a3
3 changed files with 15 additions and 17 deletions
|
@ -25,6 +25,8 @@ class Playbin : GLib.Object {
|
||||||
|
|
||||||
public PlaybinState state { get; private set; default = PlaybinState.STOPPED; }
|
public PlaybinState state { get; private set; default = PlaybinState.STOPPED; }
|
||||||
|
|
||||||
|
public Song? current_song { get; private set; default = null; }
|
||||||
|
|
||||||
// true if a timer should update the position property
|
// true if a timer should update the position property
|
||||||
private bool update_position = false;
|
private bool update_position = false;
|
||||||
public int64 position { get; private set; default = 0; }
|
public int64 position { get; private set; default = 0; }
|
||||||
|
@ -34,7 +36,7 @@ class Playbin : GLib.Object {
|
||||||
|
|
||||||
// sent when a new song starts playing
|
// sent when a new song starts playing
|
||||||
// continues: whether the track is a gapless continuation
|
// continues: whether the track is a gapless continuation
|
||||||
public signal void now_playing (bool continues, uint index, Song song);
|
public signal void now_playing (bool continues);
|
||||||
public signal void stopped ();
|
public signal void stopped ();
|
||||||
|
|
||||||
// the index of the track in the play queue that is currently playing
|
// the index of the track in the play queue that is currently playing
|
||||||
|
@ -183,7 +185,8 @@ class Playbin : GLib.Object {
|
||||||
var now_playing = (Song) play_queue.get_item (this.current_position);
|
var now_playing = (Song) play_queue.get_item (this.current_position);
|
||||||
if (this.api.stream_uri (now_playing.id) == (string) this.playbin.current_uri) {
|
if (this.api.stream_uri (now_playing.id) == (string) this.playbin.current_uri) {
|
||||||
if (continues) {
|
if (continues) {
|
||||||
this.now_playing (true, this.current_position, now_playing);
|
this.current_song = now_playing;
|
||||||
|
this.now_playing (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.current_position+1 < play_queue.get_n_items ()) {
|
if (this.current_position+1 < play_queue.get_n_items ()) {
|
||||||
|
@ -238,7 +241,7 @@ class Playbin : GLib.Object {
|
||||||
// playbin.uri wont match up with the current track's stream uri and we can
|
// playbin.uri wont match up with the current track's stream uri and we can
|
||||||
// fix it there
|
// fix it there
|
||||||
|
|
||||||
this.now_playing (false, position, song);
|
this.current_song = song;
|
||||||
this.position = 0;
|
this.position = 0;
|
||||||
this.duration = 1;
|
this.duration = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,21 +103,21 @@ template $UiWindow: Adw.ApplicationWindow {
|
||||||
styles [ "heading" ]
|
styles [ "heading" ]
|
||||||
xalign: 0;
|
xalign: 0;
|
||||||
halign: start;
|
halign: start;
|
||||||
label: bind $song_title (template.song) as <string>;
|
label: bind $song_title (template.playbin as <$Playbin>.current_song) as <string>;
|
||||||
ellipsize: end;
|
ellipsize: end;
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
styles [ "caption" ]
|
styles [ "caption" ]
|
||||||
xalign: 0;
|
xalign: 0;
|
||||||
label: bind $song_artist (template.song) as <string>;
|
label: bind $song_artist (template.playbin as <$Playbin>.current_song) as <string>;
|
||||||
ellipsize: end;
|
ellipsize: end;
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
styles [ "caption" ]
|
styles [ "caption" ]
|
||||||
xalign: 0;
|
xalign: 0;
|
||||||
label: bind $song_album (template.song) as <string>;
|
label: bind $song_album (template.playbin as <$Playbin>.current_song) as <string>;
|
||||||
ellipsize: end;
|
ellipsize: end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,6 @@ class Ui.Window : Adw.ApplicationWindow {
|
||||||
set { this.playbin.mute = value; }
|
set { this.playbin.mute = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Song? song { get; set; default = null; }
|
|
||||||
|
|
||||||
private Cancellable cancel_loading_art;
|
private Cancellable cancel_loading_art;
|
||||||
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; }
|
||||||
|
@ -60,13 +58,11 @@ class Ui.Window : Adw.ApplicationWindow {
|
||||||
this.setup.connected.connect ((api) => {
|
this.setup.connected.connect ((api) => {
|
||||||
this.playbin.api = api;
|
this.playbin.api = api;
|
||||||
|
|
||||||
this.playbin.now_playing.connect ((continues, position, song) => {
|
this.playbin.now_playing.connect ((continues) => {
|
||||||
this.song = song;
|
api.scrobble.begin (playbin.current_song.id);
|
||||||
api.scrobble.begin (song.id);
|
this.play_queue.selection.playbin_select (playbin.current_position);
|
||||||
this.play_queue.selection.playbin_select (position);
|
|
||||||
});
|
});
|
||||||
this.playbin.stopped.connect (() => {
|
this.playbin.stopped.connect (() => {
|
||||||
this.song = null;
|
|
||||||
this.play_queue.selection.playbin_select (this.play_queue_store.get_n_items ());
|
this.play_queue.selection.playbin_select (this.play_queue_store.get_n_items ());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -98,17 +94,17 @@ class Ui.Window : Adw.ApplicationWindow {
|
||||||
|
|
||||||
this.sidebar.select_row (this.sidebar.get_row_at_index (0));
|
this.sidebar.select_row (this.sidebar.get_row_at_index (0));
|
||||||
|
|
||||||
this.notify["song"].connect (() => {
|
this.playbin.notify["current-song"].connect (() => {
|
||||||
if (this.cancel_loading_art != null) {
|
if (this.cancel_loading_art != null) {
|
||||||
this.cancel_loading_art.cancel ();
|
this.cancel_loading_art.cancel ();
|
||||||
}
|
}
|
||||||
this.cancel_loading_art = new GLib.Cancellable ();
|
this.cancel_loading_art = new GLib.Cancellable ();
|
||||||
|
|
||||||
this.playing_cover_art = Gdk.Paintable.empty (1, 1);
|
this.playing_cover_art = Gdk.Paintable.empty (1, 1);
|
||||||
if (this.song != null) {
|
if (playbin.current_song != null) {
|
||||||
this.cover_art_loading = true;
|
this.cover_art_loading = true;
|
||||||
|
|
||||||
string song_id = this.song.id;
|
string song_id = playbin.current_song.id;
|
||||||
public_api.cover_art.begin (song_id, 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));
|
||||||
|
@ -122,7 +118,6 @@ class Ui.Window : Adw.ApplicationWindow {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.song = null;
|
|
||||||
|
|
||||||
this.playbin.notify["position"].connect (() => {
|
this.playbin.notify["position"].connect (() => {
|
||||||
// only set if we aren't seeking
|
// only set if we aren't seeking
|
||||||
|
|
Loading…
Reference in a new issue