Fix #703: don't crash if there are fewer than 20 random albums
This commit is contained in:
@@ -2,6 +2,7 @@ package backend
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@@ -480,11 +481,15 @@ func (p *PlaybackManager) PlaySimilarSongs(id string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PlaybackManager) PlayRandomAlbums(genreName string) error {
|
func (p *PlaybackManager) PlayRandomAlbums(genreName string) error {
|
||||||
|
mp := p.engine.sm.GetServer()
|
||||||
|
if mp == nil {
|
||||||
|
return errors.New("logged out")
|
||||||
|
}
|
||||||
|
|
||||||
if p.engine.replayGainCfg.Mode == ReplayGainAuto {
|
if p.engine.replayGainCfg.Mode == ReplayGainAuto {
|
||||||
p.SetReplayGainMode(player.ReplayGainAlbum)
|
p.SetReplayGainMode(player.ReplayGainAlbum)
|
||||||
}
|
}
|
||||||
|
|
||||||
mp := p.engine.sm.Server
|
|
||||||
var options mediaprovider.AlbumFilterOptions
|
var options mediaprovider.AlbumFilterOptions
|
||||||
if genreName != "" {
|
if genreName != "" {
|
||||||
options = mediaprovider.AlbumFilterOptions{
|
options = mediaprovider.AlbumFilterOptions{
|
||||||
@@ -495,6 +500,9 @@ func (p *PlaybackManager) PlayRandomAlbums(genreName string) error {
|
|||||||
insertMode := Replace
|
insertMode := Replace
|
||||||
for i := 0; i < 20; i++ {
|
for i := 0; i < 20; i++ {
|
||||||
al := iter.Next()
|
al := iter.Next()
|
||||||
|
if al == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
if al, err := mp.GetAlbum(al.ID); err == nil {
|
if al, err := mp.GetAlbum(al.ID); err == nil {
|
||||||
p.LoadTracks(al.Tracks, insertMode, false)
|
p.LoadTracks(al.Tracks, insertMode, false)
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user