feat: implements stop-control-card
This commit is contained in:
parent
3d8b4ed976
commit
8588363033
30
marlinbox.go
30
marlinbox.go
@ -18,6 +18,7 @@ type MarlinBox struct {
|
|||||||
CurrentID string `json:"-"`
|
CurrentID string `json:"-"`
|
||||||
Volume float64 `json:"-"`
|
Volume float64 `json:"-"`
|
||||||
NextSong bool `json:"-"`
|
NextSong bool `json:"-"`
|
||||||
|
Stop bool `json:"-"`
|
||||||
Playlist []*PlayCard `json:"playlist,omitempty"`
|
Playlist []*PlayCard `json:"playlist,omitempty"`
|
||||||
ControlCards []*ControlCard `json:"controlcards,omitempty"`
|
ControlCards []*ControlCard `json:"controlcards,omitempty"`
|
||||||
Device *evdev.InputDevice `json:"-"`
|
Device *evdev.InputDevice `json:"-"`
|
||||||
@ -135,6 +136,11 @@ func (mb *MarlinBox) GetCurrentCard() {
|
|||||||
for _, c := range mb.ControlCards {
|
for _, c := range mb.ControlCards {
|
||||||
if mb.CurrentID == c.ID {
|
if mb.CurrentID == c.ID {
|
||||||
switch c.Function {
|
switch c.Function {
|
||||||
|
case "stop":
|
||||||
|
if mb.Player != nil && mb.Player.IsPlaying() {
|
||||||
|
mb.Stop = true
|
||||||
|
}
|
||||||
|
return
|
||||||
case "vol+":
|
case "vol+":
|
||||||
if mb.Volume < 1.0 {
|
if mb.Volume < 1.0 {
|
||||||
mb.Volume = mb.Volume + 0.2
|
mb.Volume = mb.Volume + 0.2
|
||||||
@ -196,12 +202,20 @@ func (mb *MarlinBox) GetCurrentCard() {
|
|||||||
func (mb *MarlinBox) Play() {
|
func (mb *MarlinBox) Play() {
|
||||||
go func() {
|
go func() {
|
||||||
var ready chan struct{}
|
var ready chan struct{}
|
||||||
|
if mb.CurrentPlayCard == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
playingID := mb.CurrentPlayCard.ID
|
playingID := mb.CurrentPlayCard.ID
|
||||||
|
|
||||||
for _, file := range mb.CurrentPlayCard.File {
|
for _, file := range mb.CurrentPlayCard.File {
|
||||||
if playingID != mb.CurrentPlayCard.ID {
|
if mb.Stop {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if mb.CurrentPlayCard == nil || playingID != mb.CurrentPlayCard.ID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.Open(file)
|
f, err := os.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -228,13 +242,14 @@ func (mb *MarlinBox) Play() {
|
|||||||
mb.Player.Play()
|
mb.Player.Play()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if mb.CurrentPlayCard.ID != playingID {
|
if mb.Stop {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if mb.CurrentPlayCard != nil && mb.CurrentPlayCard.ID != playingID {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if mb.NextSong {
|
if mb.NextSong {
|
||||||
mb.Player.Pause()
|
|
||||||
mb.Player.Close()
|
|
||||||
mb.NextSong = false
|
mb.NextSong = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -247,11 +262,12 @@ func (mb *MarlinBox) Play() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mb.Player.Pause()
|
||||||
|
mb.Player.Close()
|
||||||
|
mb.PlayerContext.Suspend()
|
||||||
}
|
}
|
||||||
|
mb.Stop = false
|
||||||
mb.CurrentPlayCard = nil
|
mb.CurrentPlayCard = nil
|
||||||
mb.Player.Pause()
|
|
||||||
mb.Player.Close()
|
|
||||||
mb.PlayerContext.Suspend()
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user