Add basic web interface
This commit is contained in:
parent
9bbe36d2d8
commit
74c1ce47f1
15
main.go
15
main.go
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user