simple playback

This commit is contained in:
Erica Z 2024-10-10 20:04:55 +00:00
parent 88adebde64
commit 119a15eb3d
6 changed files with 26 additions and 0 deletions

View file

@ -356,4 +356,8 @@ public class Wavelet.Subsonic : Object {
assert (reader.get_error () == null);
}
public string stream_uri (string id) {
return @"$(this.url)/rest/stream?id=$(id)&$(this.parameters)";
}
}

View file

@ -19,6 +19,7 @@
*/
Sqlite.Database config_db;
Gst.Element playbin;
public class Wavelet.Application : Adw.Application {
public Application () {
@ -27,6 +28,9 @@ public class Wavelet.Application : Adw.Application {
flags: ApplicationFlags.DEFAULT_FLAGS
);
playbin = Gst.ElementFactory.make ("playbin3", null);
assert (playbin != null);
var app_config_dir = Path.build_filename (Environment.get_user_config_dir (), "wavelet");
try {
File.new_build_filename (app_config_dir).make_directory_with_parents ();
@ -83,6 +87,12 @@ public class Wavelet.Application : Adw.Application {
win.shuffle_all_tracks.sensitive = true;
});
});
win.play_queue.play_now.connect ((song) => {
playbin.set_state (Gst.State.READY);
playbin.set ("uri", api.stream_uri (song.id));
playbin.set_state (Gst.State.PLAYING);
});
});
win.setup.load (config_db);
}

View file

@ -23,6 +23,8 @@ int main (string[] args) {
Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
Intl.textdomain (Config.GETTEXT_PACKAGE);
Gst.init (ref args);
var app = new Wavelet.Application ();
return app.run (args);
}

View file

@ -11,6 +11,7 @@ wavelet_sources = [
wavelet_deps = [
config_dep,
dependency('gstreamer-1.0'),
dependency('gtk4'),
dependency('json-glib-1.0'),
dependency('libadwaita-1', version: '>= 1.4'),

View file

@ -10,6 +10,8 @@ template $WaveletPlayQueue: Adw.NavigationPage {
ScrolledWindow {
ListView list_view {
single-click-activate: true;
factory: BuilderListItemFactory {
template ListItem {
child: Label {

View file

@ -25,9 +25,16 @@ public class Wavelet.PlayQueue : Adw.NavigationPage {
private ListStore songs;
private uint current;
public signal void play_now (Song song);
construct {
this.songs = new ListStore (typeof (Song));
this.list_view.model = new Gtk.NoSelection (this.songs);
this.list_view.activate.connect ((position) => {
Song song = (Song) this.songs.get_item(position);
this.play_now (song);
});
}
public void clear () {