Add basic web interface

This commit is contained in:
nemunaire 2018-12-16 00:23:56 +01:00
parent 9bbe36d2d8
commit 74c1ce47f1
1 changed files with 15 additions and 0 deletions

15
main.go
View File

@ -5,6 +5,7 @@ import (
"io"
"log"
"math/rand"
"net/http"
"os"
"time"
@ -50,6 +51,7 @@ func loadFile(path string) (s beep.Streamer, err error) {
}
func main() {
var bind = flag.String("bind", "127.0.0.1:8080", "Bind port/socket")
flag.Parse()
if len(flag.Args()) < 2 {
@ -85,6 +87,17 @@ func main() {
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
speaker.Init(SampleRate, SampleRate.N(time.Second/10))
@ -98,6 +111,8 @@ func main() {
loop:
for {
select{
case <-stop:
break loop
case t := <-ticker.C:
if volume.Volume < 0 {
volume.Volume += 0.01