fixed repeatOne/ same track twice in a row issues

This commit is contained in:
2026-02-16 02:45:51 -05:00
parent 95e1b32e86
commit 419fec1672
4 changed files with 33 additions and 6 deletions
+6
View File
@@ -38,6 +38,7 @@ type Player struct {
volume *effects.Volume
speakerStreamer beep.Streamer
playbackFinishedHandler func()
trackChangeID uint64
}
// State represents the current playback state.
@@ -223,9 +224,14 @@ func (p *Player) emitTrackChanged() {
speaker.Unlock()
}
// Increment track change ID so the frontend can detect changes
// even when the same file plays consecutively.
p.trackChangeID++
// Emit comprehensive track info
trackInfo["trackLength"] = trackLengthSecs
trackInfo["seekPosition"] = seekPosition
trackInfo["trackChangeId"] = p.trackChangeID
runtime.EventsEmit(p.ctx, events.TrackChanged, trackInfo)
p.logger.Info("Emitting TrackChangedEvent with track info", "trackInfo", trackInfo)
+19 -1
View File
@@ -653,7 +653,8 @@ func (q *Queue) RemoveTrack(position int) {
q.emitQueueChanged()
}
// Next advances to the next track.
// Next advances to the next track. In RepeatOne mode, the current
// track is replayed instead of advancing.
func (q *Queue) Next() {
q.mu.Lock()
defer q.mu.Unlock()
@@ -662,6 +663,14 @@ func (q *Queue) Next() {
return
}
// Repeat One: replay the current track.
if q.repeatMode == RepeatOne {
q.playCurrentTrack()
q.emitQueueChanged()
return
}
nextIdx := q.nextIndex()
if nextIdx == -1 {
q.onQueueExhausted()
@@ -675,6 +684,7 @@ func (q *Queue) Next() {
}
// Previous goes to the previous track (or restarts current if >3s in).
// In RepeatOne mode, the current track is replayed instead of navigating.
func (q *Queue) Previous() {
q.mu.Lock()
defer q.mu.Unlock()
@@ -683,6 +693,14 @@ func (q *Queue) Previous() {
return
}
// Repeat One: replay the current track.
if q.repeatMode == RepeatOne {
q.playCurrentTrack()
q.emitQueueChanged()
return
}
// If more than 3 seconds into the track, restart it.
if q.player != nil {
posSecs, err := q.player.CurrentPositionSeconds()