From 2a4bf52c3774d82b975262dc7e369c79df152b20 Mon Sep 17 00:00:00 2001 From: Phil Hoffmann Date: Wed, 20 Dec 2023 20:52:15 +0100 Subject: [PATCH] Fixed a bug where the music playlist would not update visually after loading --- .../audio/players/bufferedaudioplayer.cpp | 6 ++-- .../audio/testresolvingaudioplaylist.cpp | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/tools/audio/players/bufferedaudioplayer.cpp b/src/tools/audio/players/bufferedaudioplayer.cpp index 1cd4e082..7f72073a 100644 --- a/src/tools/audio/players/bufferedaudioplayer.cpp +++ b/src/tools/audio/players/bufferedaudioplayer.cpp @@ -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(); } diff --git a/tests/tools/audio/testresolvingaudioplaylist.cpp b/tests/tools/audio/testresolvingaudioplaylist.cpp index ee160823..bc7eebc4 100644 --- a/tests/tools/audio/testresolvingaudioplaylist.cpp +++ b/tests/tools/audio/testresolvingaudioplaylist.cpp @@ -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" @@ -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(u"testing"_s, networkManager.get()); auto testingDir = SettingsManager::getPath(u"testing"_s); @@ -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"