Skip to content

Commit

Permalink
Fix "Insert Random Item from Playlist" not being random
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulp committed Sep 10, 2024
1 parent 050f33a commit a0fba43
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/playlist/Playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,22 @@ int Playlist::Load(Json::Value& config) {
LogDebug(VB_PLAYLIST, "Loading MainPlaylist:\n");
const Json::Value playlist = config["mainPlaylist"];

if ((m_loadStartPos >= 0) && (m_loadStartPos > origEntryCount))
if ((m_loadStartPos >= 0) && (m_loadStartPos > origEntryCount)) {
startPos = m_loadStartPos - origEntryCount;
else
} else if (m_loadStartPos == -2 && m_loadEndPos == 0) {
//random single item
int l = playlist.size();
if (l > 1) {
startPos = std::rand() % l;
maxEntries = 1;
}
} else {
startPos = 0;
}

if (startPos < playlist.size())
if (startPos < playlist.size()) {
LoadJSONIntoPlaylist(m_mainPlaylist, playlist, startPos, maxEntries);
}

origEntryCount += playlist.size();
}
Expand Down Expand Up @@ -1183,7 +1192,7 @@ int Playlist::Play(const char* filename, const int position, const int repeat, c
if (p == -2) {
// random
int l = m_mainPlaylist.size();
if (l > 2) {
if (l > 1) {
p = std::rand() % l;
p = p + m_leadIn.size();
}
Expand Down

0 comments on commit a0fba43

Please sign in to comment.