diff options
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) + } } |