Skip to content

Commit

Permalink
Fixed a bug where the music playlist would not update visually after …
Browse files Browse the repository at this point in the history
…loading
  • Loading branch information
PhilInTheGaps committed Dec 20, 2023
1 parent a7340be commit 2a4bf52
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/tools/audio/players/bufferedaudioplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,10 @@ void BufferedAudioPlayer::applyShuffleMode()
{
qCDebug(gmAudioBufferedPlayer()) << "Applying shuffle mode" << m_element->mode();

if (m_element->mode() != AudioElement::Mode::RandomList) return;
if (m_element->mode() == AudioElement::Mode::RandomList)
{
m_playlist->shuffle();
}

m_playlist->shuffle();
emit playlistChanged();
}
33 changes: 33 additions & 0 deletions tests/tools/audio/testresolvingaudioplaylist.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "settings/settingsmanager.h"
#include "src/services/youtube/youtube.h"
#include "src/tools/audio/playlist/resolvingaudioplaylist.h"
#include "testhelper/abstractmocknetworkmanager.h"
#include "testhelper/abstracttest.h"
Expand Down Expand Up @@ -50,6 +51,8 @@ class ResolvingAudioPlaylistTest : public AbstractTest
QDesktopServices::setUrlHandler(u"http"_s, networkManager.get(), "simulateBrowser");
QDesktopServices::setUrlHandler(u"https"_s, networkManager.get(), "simulateBrowser");

Services::YouTube::instance()->setNetworkManager(networkManager.get());

m_playlist = std::make_unique<ResolvingAudioPlaylist>(u"testing"_s, networkManager.get());

auto testingDir = SettingsManager::getPath(u"testing"_s);
Expand Down Expand Up @@ -110,4 +113,34 @@ TEST_F(ResolvingAudioPlaylistTest, CanResolveWebPlaylists)
});
}

TEST_F(ResolvingAudioPlaylistTest, CanResolveYouTubePlaylist)
{
auto *yt = new AudioFile(u"https://www.youtube.com/playlist?list=PL53mjgVKFq7yu0LdAvpp42ZGLzRCkFKuz"_s,
AudioFile::Source::Youtube, u""_s, nullptr);
m_playlist->setFiles({yt});

auto future = m_playlist->resolve();
testFuture(future, "resolve()", [this, future]() {
EXPECT_FALSE(future.isCanceled());
EXPECT_FALSE(m_playlist->isEmpty());
EXPECT_GT(m_playlist->length(), 1);
});
}

TEST_F(ResolvingAudioPlaylistTest, CanResolveMixedPlaylist)
{
auto *m3u = new AudioFile(u"/test.m3u"_s, AudioFile::Source::File, u""_s, nullptr);
auto *pls = new AudioFile(u"/test.pls"_s, AudioFile::Source::File, u""_s, nullptr);
auto *yt = new AudioFile(u"https://www.youtube.com/playlist?list=PL53mjgVKFq7yu0LdAvpp42ZGLzRCkFKuz"_s,
AudioFile::Source::Youtube, u""_s, nullptr);
m_playlist->setFiles({m3u, pls, yt});

auto future = m_playlist->resolve();
testFuture(future, "resolve()", [this, future]() {
EXPECT_FALSE(future.isCanceled());
EXPECT_FALSE(m_playlist->isEmpty());
EXPECT_GT(m_playlist->length(), 7);
});
}

#include "testresolvingaudioplaylist.moc"

0 comments on commit 2a4bf52

Please sign in to comment.