stopped player plays queue on play button click if queue is not empty. seek bar bigger.
This commit is contained in:
@@ -133,6 +133,11 @@ func (q *Queue) registerEventHandlers() {
|
||||
return
|
||||
}
|
||||
|
||||
runtime.EventsOn(q.ctx, events.RequestPlay, func(_ ...any) {
|
||||
q.logger.Info("Received RequestPlay")
|
||||
q.PlayFromStart()
|
||||
})
|
||||
|
||||
runtime.EventsOn(q.ctx, events.RequestNext, func(_ ...any) {
|
||||
q.logger.Info("Received RequestNext")
|
||||
q.Next()
|
||||
@@ -703,6 +708,33 @@ func (q *Queue) Previous() {
|
||||
q.emitQueueChanged()
|
||||
}
|
||||
|
||||
// PlayFromStart restarts playback from the beginning of the queue.
|
||||
// If shuffle is enabled, a new shuffle order is generated and playback
|
||||
// starts from a random track. This is a no-op when a track is already
|
||||
// active (currentIndex != -1) or the queue is empty.
|
||||
func (q *Queue) PlayFromStart() {
|
||||
q.mu.Lock()
|
||||
defer q.mu.Unlock()
|
||||
|
||||
if q.currentIndex != -1 {
|
||||
return
|
||||
}
|
||||
|
||||
if len(q.tracks) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if q.shuffleMode {
|
||||
q.generateShuffleOrder()
|
||||
q.currentIndex = q.shuffleOrder[0]
|
||||
} else {
|
||||
q.currentIndex = 0
|
||||
}
|
||||
|
||||
q.playCurrentTrack()
|
||||
q.emitQueueChanged()
|
||||
}
|
||||
|
||||
// PlayIndex jumps to and plays the track at the given index.
|
||||
func (q *Queue) PlayIndex(index int) {
|
||||
q.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user