From 04ed13ca73442d90a15d1b0b3816ed5ee8f130d8 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 8 Dec 2024 19:56:52 +0100 Subject: Add experimental streaming with PipeWire This allows to stream sound from a Linux PC with PipeWire sound system to soundboxes. Currently PipeWire capture nodes are used. They should be connected to the monitor output of the default sound sink manually. --- main.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 060f76c..658f76b 100644 --- a/main.go +++ b/main.go @@ -42,7 +42,7 @@ type State struct { Theme *material.Theme IsPlaying bool Title string - UrlSelector widget.Enum + SourceSelector widget.Enum PlayPauseButton widget.Clickable PlayerContext context.Context PlayerCancel context.CancelFunc @@ -105,7 +105,7 @@ func (ui *Ui) HandleInputs(gtx layout.Context) { if ui.State.IsPlaying { ui.State.PlayerCancel() } else { - if ui.State.UrlSelector.Value == "" { + if ui.State.SourceSelector.Value == "" { log.Println("A URL has to be selected.") } else { ui.State.PlayerContext, ui.State.PlayerCancel = context.WithCancel(context.Background()) @@ -115,7 +115,7 @@ func (ui *Ui) HandleInputs(gtx layout.Context) { targets = append(targets, net.HardwareAddr(entry.Mac)) } } - go play(ui.State.PlayerContext, ui.State.UrlSelector.Value, targets, ui) + go play(ui.State.PlayerContext, ui.State.SourceSelector.Value, targets, ui) } } } @@ -149,9 +149,12 @@ func (ui *Ui) Layout(gtx layout.Context) layout.Dimensions { layout.Rigid(layout.Spacer{Height: unit.Dp(25)}.Layout), } + entries = append(entries, layout.Rigid(material.RadioButton( + ui.State.Theme, &ui.State.SourceSelector, + "PipeWire", "This device (experimental)").Layout)) for _, url := range ui.State.Config.URLs { entries = append(entries, layout.Rigid(material.RadioButton( - ui.State.Theme, &ui.State.UrlSelector, + ui.State.Theme, &ui.State.SourceSelector, url.Url, url.Name).Layout)) } @@ -174,7 +177,12 @@ func play(ctx context.Context, url string, targets []net.HardwareAddr, ui *Ui) { setPlayingState(true) defer setPlayingState(false) - err := soundbox.StreamURLContext(ctx, url, targets) + var err error + if url == "PipeWire" { + err = soundbox.StreamPipewireContext(ctx, targets) + } else { + err = soundbox.StreamURLContext(ctx, url, targets) + } if err != nil { log.Println(err) } -- cgit v1.2.3-70-g09d2