Async music preview
This commit is contained in:
parent
d2194e9e00
commit
c00db7d6f7
@ -1,10 +1,11 @@
|
||||
#include "MusicPreview.hpp"
|
||||
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
namespace MusicSelect {
|
||||
|
||||
void MusicPreview::play(std::optional<fs::path> music_path, std::optional<sf::Music::TimeSpan> loop) {
|
||||
void MusicPreview::play_async(std::optional<fs::path> music_path, std::optional<sf::Music::TimeSpan> 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<fs::path> music_path, std::optional<sf::Music::TimeSpan> loop) {
|
||||
std::thread(&MusicPreview::play_async, this, music_path, loop).detach();
|
||||
}
|
||||
|
||||
void MusicPreview::update() {
|
||||
if (m_music_loop) {
|
||||
m_music_loop->music.setVolume(
|
||||
|
@ -23,6 +23,7 @@ namespace MusicSelect {
|
||||
void play(std::optional<fs::path> music_path, std::optional<sf::Music::TimeSpan> loop);
|
||||
void update();
|
||||
private:
|
||||
void play_async(std::optional<fs::path> music_path, std::optional<sf::Music::TimeSpan> loop);
|
||||
std::optional<MusicLoop> m_music_loop;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user