Skip to content

Commit fcdba09

Browse files
committed
fix(queue): fixed loop one
1 parent 1634b0e commit fcdba09

File tree

1 file changed

+23
-43
lines changed

1 file changed

+23
-43
lines changed

internal/ui/update_messages.go

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,17 @@ func (m model) handleStatus(msg statusMsg) (tea.Model, tea.Cmd) {
200200
var cmds []tea.Cmd
201201
cmds = append(cmds, syncPlayerCmd())
202202

203+
// Queue ended
203204
if m.playerStatus.Path == "" || m.playerStatus.Path == "<nil>" || len(m.queue) == 0 {
204205
m.queue = []api.Song{}
205206
m.lastPlayedSongPath = ""
206207

207-
// Clear MRPIS after queue ends
208+
// Clear MRPIS
208209
if m.dbusInstance != nil {
209210
m.dbusInstance.ClearMetadata()
210211
}
211212

212-
// Clear album art after queue ends
213+
// Clear album art
213214
if api.AppConfig.Theme.DisplayAlbumArt {
214215
m.coverArt = nil
215216
}
@@ -218,19 +219,33 @@ func (m model) handleStatus(msg statusMsg) (tea.Model, tea.Cmd) {
218219
return m, tea.Batch(cmds...)
219220
}
220221

221-
// Check if next song is playing
222-
if len(m.queue) > 0 && m.playerStatus.Path != "" && m.playerStatus.Path != m.lastPlayedSongPath {
223-
currentSong := m.queue[m.queueIndex]
222+
// Song changed
223+
if m.playerStatus.Path != m.lastPlayedSongPath {
224+
225+
// Update queue index after mpv song change
226+
if !strings.Contains(m.playerStatus.Path, "id="+m.queue[m.queueIndex].ID) {
227+
nextIndex := m.queueIndex + 1
228+
229+
if nextIndex < len(m.queue) {
230+
m.queueIndex = nextIndex
231+
} else if nextIndex >= len(m.queue) && m.loopMode == LoopAll {
232+
m.queueIndex = 0
233+
}
234+
}
224235

225-
m.lastPlayedSongPath = m.playerStatus.Path
226-
m.scrobbled = false
236+
// Update queue
237+
m.syncNextSong()
238+
239+
currentSong := m.queue[m.queueIndex]
240+
m.lastPlayedSongPath = m.playerStatus.Path // Update previous song
241+
m.scrobbled = false // Reset scrobble status
227242

228243
// Setup metadata
229244
metadata := integration.Metadata{
230245
Title: currentSong.Title,
231246
Artist: currentSong.Artist,
232247
Album: currentSong.Album,
233-
Duration: float64(currentSong.Duration), // Cast int to float64
248+
Duration: float64(currentSong.Duration),
234249
ImageURL: api.SubsonicCoverArtUrl(currentSong.ID, 500),
235250
Rating: math.Round(float64(currentSong.Rating*10)) / 10,
236251
}
@@ -289,41 +304,6 @@ func (m model) handleStatus(msg statusMsg) (tea.Model, tea.Cmd) {
289304
}
290305
}
291306

292-
if m.playerStatus.Path != "" &&
293-
m.playerStatus.Path != "<nil>" &&
294-
len(m.queue) > 0 &&
295-
!strings.Contains(m.playerStatus.Path, "id="+m.queue[m.queueIndex].ID) {
296-
297-
nextIndex := m.queueIndex + 1
298-
m.scrobbled = false
299-
300-
// Queue next song
301-
if nextIndex < len(m.queue) {
302-
m.queueIndex = nextIndex
303-
}
304-
305-
nextNextIndex := -1
306-
switch m.loopMode {
307-
case LoopOne:
308-
nextNextIndex = nextIndex
309-
case LoopNone:
310-
nextNextIndex = nextIndex + 1
311-
case LoopAll:
312-
if nextIndex == len(m.queue)-1 {
313-
nextNextIndex = 0
314-
} else {
315-
nextNextIndex = nextIndex + 1
316-
}
317-
}
318-
319-
// Queue next next song
320-
if nextNextIndex < len(m.queue) {
321-
player.UpdateNextSong(m.queue[nextNextIndex].ID)
322-
} else { // End of queue, clear MPV
323-
go player.UpdateNextSong("")
324-
}
325-
}
326-
327307
return m, tea.Batch(cmds...)
328308
}
329309

0 commit comments

Comments
 (0)