Add basic web interface

This commit is contained in:
nemunaire 2018-12-16 00:23:56 +01:00
parent 9bbe36d2d8
commit 74c1ce47f1

15
main.go
View File

@ -5,6 +5,7 @@ import (
"io" "io"
"log" "log"
"math/rand" "math/rand"
"net/http"
"os" "os"
"time" "time"
@ -50,6 +51,7 @@ func loadFile(path string) (s beep.Streamer, err error) {
} }
func main() { func main() {
var bind = flag.String("bind", "127.0.0.1:8080", "Bind port/socket")
flag.Parse() flag.Parse()
if len(flag.Args()) < 2 { if len(flag.Args()) < 2 {
@ -85,6 +87,17 @@ func main() {
return playlist[playedItem] return playlist[playedItem]
}) })
stop := make(chan struct{})
// Prepare stop via http
http.HandleFunc("/stop", func(w http.ResponseWriter, _ *http.Request) {
w.Write([]byte("Ok"))
close(stop)
})
go func() {
log.Fatal(http.ListenAndServe(*bind, nil))
}()
// Prepare sound player // Prepare sound player
speaker.Init(SampleRate, SampleRate.N(time.Second/10)) speaker.Init(SampleRate, SampleRate.N(time.Second/10))
@ -98,6 +111,8 @@ func main() {
loop: loop:
for { for {
select{ select{
case <-stop:
break loop
case t := <-ticker.C: case t := <-ticker.C:
if volume.Volume < 0 { if volume.Volume < 0 {
volume.Volume += 0.01 volume.Volume += 0.01