Compare commits
1 Commits
1fbd6bce2d
...
ff027bbcdd
Author | SHA1 | Date | |
---|---|---|---|
ff027bbcdd |
22
music.go
22
music.go
|
@ -26,10 +26,13 @@ func (s *Sonar) Watch() {
|
||||||
if err := p.cmd.Wait(); err != nil {
|
if err := p.cmd.Wait(); err != nil {
|
||||||
log.Error("Player.Watch: p.cmd.Wait: %s", err)
|
log.Error("Player.Watch: p.cmd.Wait: %s", err)
|
||||||
}
|
}
|
||||||
|
p.cmd = nil
|
||||||
|
|
||||||
// Next track?
|
// Next track?
|
||||||
log.Info("Track ended, play next")
|
log.Info("Track ended, play next")
|
||||||
s.PlayNext()
|
if err := s.PlayNext(); err != nil {
|
||||||
|
log.Info("EOF: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
|
@ -53,15 +56,17 @@ func (p *Player) Stop() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
p.cmd = nil
|
p.cmd = nil
|
||||||
|
p.playlist = []string{}
|
||||||
p.index = 0
|
p.index = 0
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next returns the next song.
|
// Next returns the next song.
|
||||||
func (p *Player) Next() (string, bool) {
|
func (p *Player) Next() (string, bool) {
|
||||||
p.index++
|
|
||||||
if p.index < len(p.playlist) {
|
if p.index < len(p.playlist) {
|
||||||
return p.playlist[p.index], true
|
next := p.playlist[p.index]
|
||||||
|
p.index++
|
||||||
|
return next, true
|
||||||
}
|
}
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
@ -75,23 +80,18 @@ func (p *Player) Status() string {
|
||||||
var (
|
var (
|
||||||
index = p.index
|
index = p.index
|
||||||
length = len(p.playlist)
|
length = len(p.playlist)
|
||||||
pct float64
|
|
||||||
)
|
)
|
||||||
if length > 0 {
|
|
||||||
pct = float64(index / length)
|
|
||||||
}
|
|
||||||
parts = append(parts, fmt.Sprintf(
|
parts = append(parts, fmt.Sprintf(
|
||||||
"Track %d of %d (%.2f%%)",
|
"Track %d of %d",
|
||||||
index,
|
index,
|
||||||
length,
|
length,
|
||||||
pct,
|
|
||||||
))
|
))
|
||||||
|
|
||||||
// Append current track.
|
// Append current track.
|
||||||
if index < len(p.playlist) {
|
if index <= len(p.playlist) {
|
||||||
parts = append(parts, fmt.Sprintf(
|
parts = append(parts, fmt.Sprintf(
|
||||||
"Now playing: %s",
|
"Now playing: %s",
|
||||||
p.playlist[index],
|
p.playlist[index-1],
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user