Skip to content

Commit

Permalink
fix nil track after playing next
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Nov 12, 2022
1 parent ed0ebab commit feee51e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lavalink/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,6 @@ func (p *DefaultPlayer) PlayAt(track AudioTrack, start Duration, end Duration) e
func (p *DefaultPlayer) Stop() error {
p.track = nil

if p.node == nil {
return nil
}

if err := p.node.Send(StopCommand{GuildID: p.guildID}); err != nil {
return fmt.Errorf("error while stopping player: %w", err)
}
Expand Down Expand Up @@ -278,6 +274,8 @@ func (p *DefaultPlayer) Seek(position Duration) error {
}); err != nil {
return fmt.Errorf("error while seeking player: %w", err)
}
p.state.Position = position
p.state.Time = Time{Time: time.Now()}
return nil
}

Expand Down Expand Up @@ -421,7 +419,9 @@ func (p *DefaultPlayer) OnEvent(event TrackEvent) {
})

case TrackEndEvent:
p.track = nil
if e.Reason != AudioTrackEndReasonReplaced && e.Reason != AudioTrackEndReasonStopped {
p.track = nil
}
p.EmitEvent(func(l any) {
if listener := l.(PlayerEventListener); listener != nil {
listener.OnTrackEnd(p, track, e.Reason)
Expand Down

0 comments on commit feee51e

Please sign in to comment.