From b61b0521773637f1722fade6c1fd395783643d75 Mon Sep 17 00:00:00 2001 From: me Date: Thu, 10 Oct 2024 20:04:55 +0000 Subject: [PATCH] simple playback --- src/api.vala | 4 ++++ src/application.vala | 10 ++++++++++ src/main.vala | 2 ++ src/meson.build | 1 + src/play_queue.blp | 2 ++ src/play_queue.vala | 7 +++++++ 6 files changed, 26 insertions(+) diff --git a/src/api.vala b/src/api.vala index 7f084c6..b0cddce 100644 --- a/src/api.vala +++ b/src/api.vala @@ -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)"; + } } diff --git a/src/application.vala b/src/application.vala index ba9e4e3..5f84900 100644 --- a/src/application.vala +++ b/src/application.vala @@ -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); } diff --git a/src/main.vala b/src/main.vala index 23ddaba..b0be064 100644 --- a/src/main.vala +++ b/src/main.vala @@ -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); } diff --git a/src/meson.build b/src/meson.build index 5e640f6..5a4ad47 100644 --- a/src/meson.build +++ b/src/meson.build @@ -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'), diff --git a/src/play_queue.blp b/src/play_queue.blp index 4688b2e..9e0b9cd 100644 --- a/src/play_queue.blp +++ b/src/play_queue.blp @@ -10,6 +10,8 @@ template $WaveletPlayQueue: Adw.NavigationPage { ScrolledWindow { ListView list_view { + single-click-activate: true; + factory: BuilderListItemFactory { template ListItem { child: Label { diff --git a/src/play_queue.vala b/src/play_queue.vala index cae0185..9c7d2ec 100644 --- a/src/play_queue.vala +++ b/src/play_queue.vala @@ -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 () {