Skip to content

Commit

Permalink
Fix switching between tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
wildeyedskies committed Dec 21, 2020
1 parent 2eeacc6 commit 379bf65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ func handleMpvEvents(ui *Ui) {
e := <-ui.player.EventChannel
if e == nil {
break
} else if e.Event_Id == mpv.EVENT_END_FILE {
// we don't want to update anything if we're in the process of replacing the current track
} else if e.Event_Id == mpv.EVENT_END_FILE && !ui.player.ReplaceInProgress {
ui.startStopStatus.SetText("[::b]stmp: [red]stopped")
// TODO it's gross that this is here, need better event handling
if len(ui.player.Queue) > 0 {
Expand All @@ -311,6 +312,7 @@ func handleMpvEvents(ui *Ui) {
updateQueueList(ui.player, ui.queueList)
ui.player.PlayNextTrack()
} else if e.Event_Id == mpv.EVENT_START_FILE {
ui.player.ReplaceInProgress = false
ui.startStopStatus.SetText("[::b]stmp: [green]playing " + ui.player.Queue[0].Title)
updateQueueList(ui.player, ui.queueList)
}
Expand Down
10 changes: 6 additions & 4 deletions player.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ type QueueItem struct {
}

type Player struct {
Instance *mpv.Mpv
EventChannel chan *mpv.Event
Queue []QueueItem
Instance *mpv.Mpv
EventChannel chan *mpv.Event
Queue []QueueItem
ReplaceInProgress bool
}

func eventListener(m *mpv.Mpv) chan *mpv.Event {
Expand All @@ -46,7 +47,7 @@ func InitPlayer() (*Player, error) {
return nil, err
}

return &Player{mpvInstance, eventListener(mpvInstance), nil}, nil
return &Player{mpvInstance, eventListener(mpvInstance), nil, false}, nil
}

func (p *Player) PlayNextTrack() {
Expand All @@ -57,6 +58,7 @@ func (p *Player) PlayNextTrack() {

func (p *Player) Play(uri string, title string, artist string) {
p.Queue = []QueueItem{QueueItem{uri, title, artist}}
p.ReplaceInProgress = true
p.Instance.Command([]string{"loadfile", uri})
}

Expand Down

0 comments on commit 379bf65

Please sign in to comment.