diff options
author | xengineering <me@xengineering.eu> | 2024-10-03 18:16:08 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-10-06 20:13:28 +0200 |
commit | a1d91fcba108a59c440f0675dd5106422cf3ff7e (patch) | |
tree | f40aea2e6cda586da1a294b1200b55f2424c199d /main.go | |
parent | bb34d5f69ca4ad66754dd9833b9d7efee41ba4f2 (diff) | |
download | soundbox-app-a1d91fcba108a59c440f0675dd5106422cf3ff7e.tar soundbox-app-a1d91fcba108a59c440f0675dd5106422cf3ff7e.tar.zst soundbox-app-a1d91fcba108a59c440f0675dd5106422cf3ff7e.zip |
Switch from local playback to soundbox streaming
This commit replaces the local playback of the received audio content by
forwarding it to one or multiple soundbox devices.
For this purpose the soundbox-go[1] library is used.
The target devices cannot be selected via the GUI. Thus all devices are
specified in the ~/.config/soundbox/config.json file. The format has to
be looked up based on the code. Further documentation will follow.
[1]: https://xengineering.eu/git/soundbox-go
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 34 |
1 files changed, 23 insertions, 11 deletions
@@ -4,8 +4,8 @@ import ( "context" "image/color" "log" + "net" "os" - "os/exec" "sync" "gioui.org/app" @@ -15,6 +15,8 @@ import ( "gioui.org/unit" "gioui.org/widget" "gioui.org/widget/material" + + "xengineering.eu/soundbox" ) func main() { @@ -93,7 +95,7 @@ func (ui *Ui) HandleInputs(gtx layout.Context) { ui.State.PlayerCancel() } else { ui.State.PlayerContext, ui.State.PlayerCancel = context.WithCancel(context.Background()) - go mpv(ui.State.PlayerContext, ui.State.UrlEditor.Text(), ui) + go play(ui.State.PlayerContext, ui.State.UrlEditor.Text(), ui) } } } @@ -129,7 +131,7 @@ func (ui *Ui) Layout(gtx layout.Context) layout.Dimensions { }) } -func mpv(ctx context.Context, url string, ui *Ui) { +func play(ctx context.Context, url string, ui *Ui) { setPlayingState := func(isPlaying bool) { ui.State.Lock() defer ui.Window.Invalidate() @@ -144,14 +146,24 @@ func mpv(ctx context.Context, url string, ui *Ui) { } setPlayingState(true) + defer setPlayingState(false) - cmd := exec.CommandContext( - ctx, - "mpv", - "--no-video", - url, - ) - _ = cmd.Run() + config, err := loadConfig() + if err != nil { + log.Println(err) + } - setPlayingState(false) + var devices []net.HardwareAddr + for _, entry := range config.Soundboxes { + mac, err := net.ParseMAC(entry.Mac) + if err != nil { + log.Printf("Failed to parse MAC: %v", err) + } + devices = append(devices, mac) + } + + err = soundbox.StreamURLContext(ctx, url, devices) + if err != nil { + log.Println(err) + } } |