WIP: feat: add "Play next" MenuItem
This commit is contained in:
+1
-1
@@ -324,7 +324,7 @@ func (a *App) LoadSavedPlayQueue() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := a.PlaybackManager.LoadTracks(queue.Tracks, false, false); err != nil {
|
||||
if err := a.PlaybackManager.LoadTracks(queue.Tracks, Replace, false); err != nil {
|
||||
return err
|
||||
}
|
||||
if queue.TrackIndex >= 0 {
|
||||
|
||||
@@ -20,6 +20,14 @@ var (
|
||||
ReplayGainAuto = "Auto"
|
||||
)
|
||||
|
||||
type InsertQueueMode int
|
||||
|
||||
const (
|
||||
Replace InsertQueueMode = iota
|
||||
InsertNext
|
||||
Append
|
||||
)
|
||||
|
||||
// The playback loop mode (LoopNone, LoopAll, LoopOne).
|
||||
type LoopMode int
|
||||
|
||||
@@ -200,19 +208,24 @@ func (p *playbackEngine) Continue() error {
|
||||
|
||||
// Load tracks into the play queue.
|
||||
// If replacing the current queue (!appendToQueue), playback will be stopped.
|
||||
func (p *playbackEngine) LoadTracks(tracks []*mediaprovider.Track, appendToQueue, shuffle bool) error {
|
||||
if !appendToQueue {
|
||||
func (p *playbackEngine) LoadTracks(tracks []*mediaprovider.Track, insertQueueMode InsertQueueMode, shuffle bool) error {
|
||||
if insertQueueMode == Replace {
|
||||
p.player.Stop()
|
||||
p.nowPlayingIdx = -1
|
||||
p.playQueue = nil
|
||||
}
|
||||
needToSetNext := appendToQueue && len(tracks) > 0 && p.nowPlayingIdx == len(p.playQueue)-1
|
||||
needToSetNext := len(tracks) > 0 && (insertQueueMode == InsertNext || (insertQueueMode == Append && p.nowPlayingIdx == len(p.playQueue)-1))
|
||||
|
||||
newTracks := p.deepCopyTrackSlice(tracks)
|
||||
if shuffle {
|
||||
rand.Shuffle(len(newTracks), func(i, j int) { newTracks[i], newTracks[j] = newTracks[j], newTracks[i] })
|
||||
}
|
||||
p.playQueue = append(p.playQueue, newTracks...)
|
||||
|
||||
insertIdx := len(p.playQueue)
|
||||
if insertQueueMode == InsertNext {
|
||||
insertIdx = p.nowPlayingIdx + 1
|
||||
}
|
||||
p.playQueue = append(p.playQueue[:insertIdx], append(newTracks, p.playQueue[insertIdx:]...)...)
|
||||
|
||||
if needToSetNext {
|
||||
p.setNextTrack(p.nowPlayingIdx + 1)
|
||||
|
||||
+10
-10
@@ -100,27 +100,27 @@ func (p *PlaybackManager) OnPlaying(cb func()) {
|
||||
}
|
||||
|
||||
// Loads the specified album into the play queue.
|
||||
func (p *PlaybackManager) LoadAlbum(albumID string, appendToQueue bool, shuffle bool) error {
|
||||
func (p *PlaybackManager) LoadAlbum(albumID string, insertQueueMode InsertQueueMode, shuffle bool) error {
|
||||
album, err := p.engine.sm.Server.GetAlbum(albumID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return p.LoadTracks(album.Tracks, appendToQueue, shuffle)
|
||||
return p.LoadTracks(album.Tracks, insertQueueMode, shuffle)
|
||||
}
|
||||
|
||||
// Loads the specified playlist into the play queue.
|
||||
func (p *PlaybackManager) LoadPlaylist(playlistID string, appendToQueue bool, shuffle bool) error {
|
||||
func (p *PlaybackManager) LoadPlaylist(playlistID string, insertQueueMode InsertQueueMode, shuffle bool) error {
|
||||
playlist, err := p.engine.sm.Server.GetPlaylist(playlistID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return p.LoadTracks(playlist.Tracks, appendToQueue, shuffle)
|
||||
return p.LoadTracks(playlist.Tracks, insertQueueMode, shuffle)
|
||||
}
|
||||
|
||||
// Load tracks into the play queue.
|
||||
// If replacing the current queue (!appendToQueue), playback will be stopped.
|
||||
func (p *PlaybackManager) LoadTracks(tracks []*mediaprovider.Track, appendToQueue, shuffle bool) error {
|
||||
return p.engine.LoadTracks(tracks, appendToQueue, shuffle)
|
||||
func (p *PlaybackManager) LoadTracks(tracks []*mediaprovider.Track, insertQueueMode InsertQueueMode, shuffle bool) error {
|
||||
return p.engine.LoadTracks(tracks, insertQueueMode, shuffle)
|
||||
}
|
||||
|
||||
// Replaces the play queue with the given set of tracks.
|
||||
@@ -131,7 +131,7 @@ func (p *PlaybackManager) UpdatePlayQueue(tracks []*mediaprovider.Track) error {
|
||||
}
|
||||
|
||||
func (p *PlaybackManager) PlayAlbum(albumID string, firstTrack int, shuffle bool) error {
|
||||
if err := p.LoadAlbum(albumID, false, shuffle); err != nil {
|
||||
if err := p.LoadAlbum(albumID, Replace, shuffle); err != nil {
|
||||
return err
|
||||
}
|
||||
if p.engine.replayGainCfg.Mode == ReplayGainAuto {
|
||||
@@ -141,7 +141,7 @@ func (p *PlaybackManager) PlayAlbum(albumID string, firstTrack int, shuffle bool
|
||||
}
|
||||
|
||||
func (p *PlaybackManager) PlayPlaylist(playlistID string, firstTrack int, shuffle bool) error {
|
||||
if err := p.LoadPlaylist(playlistID, false, shuffle); err != nil {
|
||||
if err := p.LoadPlaylist(playlistID, Replace, shuffle); err != nil {
|
||||
return err
|
||||
}
|
||||
if p.engine.replayGainCfg.Mode == ReplayGainAuto {
|
||||
@@ -155,7 +155,7 @@ func (p *PlaybackManager) PlayTrack(trackID string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.LoadTracks([]*mediaprovider.Track{tr}, false, false)
|
||||
p.LoadTracks([]*mediaprovider.Track{tr}, Replace, false)
|
||||
if p.engine.replayGainCfg.Mode == ReplayGainAuto {
|
||||
p.SetReplayGainMode(player.ReplayGainTrack)
|
||||
}
|
||||
@@ -186,7 +186,7 @@ func (p *PlaybackManager) fetchAndPlayTracks(fetchFn func() ([]*mediaprovider.Tr
|
||||
if songs, err := fetchFn(); err != nil {
|
||||
log.Printf("error fetching tracks: %s", err.Error())
|
||||
} else {
|
||||
p.LoadTracks(songs, false, false)
|
||||
p.LoadTracks(songs, Replace, false)
|
||||
if p.engine.replayGainCfg.Mode == ReplayGainAuto {
|
||||
p.SetReplayGainMode(player.ReplayGainTrack)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user