diff --git a/src/Screens/MusicSelect/MusicPreview.cpp b/src/Screens/MusicSelect/MusicPreview.cpp index 22c9ed5..d150483 100644 --- a/src/Screens/MusicSelect/MusicPreview.cpp +++ b/src/Screens/MusicSelect/MusicPreview.cpp @@ -1,10 +1,11 @@ #include "MusicPreview.hpp" +#include #include namespace MusicSelect { - void MusicPreview::play(std::optional music_path, std::optional loop) { + void MusicPreview::play_async(std::optional music_path, std::optional loop) { m_music_loop.emplace(); if (not music_path.has_value()) { return; @@ -32,6 +33,10 @@ namespace MusicSelect { m_music_loop->music.play(); } + void MusicPreview::play(std::optional music_path, std::optional loop) { + std::thread(&MusicPreview::play_async, this, music_path, loop).detach(); + } + void MusicPreview::update() { if (m_music_loop) { m_music_loop->music.setVolume( diff --git a/src/Screens/MusicSelect/MusicPreview.hpp b/src/Screens/MusicSelect/MusicPreview.hpp index 3fbd52b..baef2f8 100644 --- a/src/Screens/MusicSelect/MusicPreview.hpp +++ b/src/Screens/MusicSelect/MusicPreview.hpp @@ -23,6 +23,7 @@ namespace MusicSelect { void play(std::optional music_path, std::optional loop); void update(); private: + void play_async(std::optional music_path, std::optional loop); std::optional m_music_loop; }; }