mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2026-03-15 14:03:17 +08:00
fix playlist index not reset to 0 when switch from random
This commit is contained in:
@@ -22,6 +22,14 @@ type PlaylistMoveCmdEvent struct {
|
||||
To int
|
||||
}
|
||||
|
||||
func PlaylistSetIndexCmd(id model.PlaylistID) event.EventId {
|
||||
return event.EventId("cmd.playlist.setindex." + id)
|
||||
}
|
||||
|
||||
type PlaylistSetIndexCmdEvent struct {
|
||||
Index int
|
||||
}
|
||||
|
||||
func PlaylistDeleteCmd(id model.PlaylistID) event.EventId {
|
||||
return event.EventId("cmd.playlist.delete." + id)
|
||||
}
|
||||
|
||||
@@ -40,12 +40,22 @@ func newPlaylist(id model.PlaylistID) *playlist {
|
||||
pl.Next(event.Data.(events.PlaylistNextCmdEvent).Remove)
|
||||
})
|
||||
global.EventManager.RegisterA(events.PlaylistModeChangeCmd(id), "internal.playlist.mode", func(event *event.Event) {
|
||||
if pl.mode == model.PlaylistModeRandom {
|
||||
pl.Index = 0
|
||||
}
|
||||
pl.mode = event.Data.(events.PlaylistModeChangeCmdEvent).Mode
|
||||
log.Infof("Playlist %s mode changed to %d", id, pl.mode)
|
||||
global.EventManager.CallA(events.PlaylistModeChangeUpdate(id), events.PlaylistModeChangeUpdateEvent{
|
||||
Mode: pl.mode,
|
||||
})
|
||||
})
|
||||
global.EventManager.RegisterA(events.PlaylistSetIndexCmd(id), "internal.playlist.setindex", func(event *event.Event) {
|
||||
index := event.Data.(events.PlaylistSetIndexCmdEvent).Index
|
||||
if index >= pl.Size() || index < 0 {
|
||||
index = 0
|
||||
}
|
||||
pl.Index = index
|
||||
})
|
||||
return pl
|
||||
}
|
||||
|
||||
@@ -144,6 +154,10 @@ func (p *playlist) Next(delete bool) {
|
||||
}
|
||||
var index int
|
||||
index = p.Index
|
||||
// add guard
|
||||
if index >= p.Size() {
|
||||
index = 0
|
||||
}
|
||||
if p.mode == model.PlaylistModeRandom {
|
||||
p.Index = rand.Intn(p.Size())
|
||||
} else if p.mode == model.PlaylistModeNormal {
|
||||
|
||||
Reference in New Issue
Block a user