Skip to content

Commit

Permalink
fixing mpd
Browse files Browse the repository at this point in the history
  • Loading branch information
tramhao committed May 21, 2021
1 parent d6b1d07 commit 5b6450d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
14 changes: 7 additions & 7 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ func (c Command) defineCommands() {

gomu.queue.pushFront(a)

if gomu.player.IsRunning() {
if err := gomu.player.Skip(); err != nil {
errorPopup(err)
}
} else {
gomu.queue.playQueue()
}
// if gomu.player.IsRunning() {
// if err := gomu.player.Skip(); err != nil {
// errorPopup(err)
// }
// } else {
gomu.queue.playQueue()
// }
}
})

Expand Down
38 changes: 26 additions & 12 deletions player/mpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type MPDPlayer struct {
volume float64
currentSong Audio
mpdPort string
done chan bool

songFinish func(Audio)
songStart func(Audio)
Expand Down Expand Up @@ -68,6 +69,7 @@ func NewMPDPlayer(volume int, mpdPort string) (*MPDPlayer, error) {
volume: initVol,
currentSong: nil,
mpdPort: mpdPort,
done: make(chan bool),
songFinish: func(Audio) {
},
songStart: func(Audio) {
Expand Down Expand Up @@ -161,22 +163,29 @@ func (p *MPDPlayer) Run(currSong Audio) (err error) {
return tracerr.Wrap(err)
}

ticker := time.NewTicker(time.Second)
go func() {
for {

status, err := p.client.Status()
if err != nil {
log.Fatalln(err)
continue
}

if status["state"] == "stop" {
select {
case <-p.done:
ticker.Stop()
p.isRunning = false
p.execSongFinish(currSong)
break
}
return

case <-ticker.C:

status, err := p.client.Status()
if err != nil {
log.Fatalln(err)
continue
}

<-time.After(time.Second)
if status["state"] == "stop" {
p.done <- true
}

}
}
}()

Expand Down Expand Up @@ -235,7 +244,9 @@ func (p *MPDPlayer) Skip() error {
}

p.isRunning = false
p.execSongFinish(p.currentSong)

p.done <- true
// p.execSongFinish(p.currentSong)

return nil
}
Expand Down Expand Up @@ -344,6 +355,9 @@ func (p *MPDPlayer) reconnect() (err error) {

func (p *MPDPlayer) keepAlive() {
for {
if p.client == nil {
p.reconnect()
}
err := p.client.Ping()
if err != nil {
log.Println("Disconnected. Reconnecting...")
Expand Down
3 changes: 1 addition & 2 deletions playingbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,7 @@ func (p *PlayingBar) updatePhoto() {

if p.albumPhoto != nil {
p.albumPhoto.Clear()
// p.albumPhoto.Destroy()
ugo.Initialize()
p.albumPhoto.Destroy()
p.albumPhoto = nil
}

Expand Down

0 comments on commit 5b6450d

Please sign in to comment.