1
0
mirror of synced 2024-11-14 10:37:40 +01:00

Async music preview

This commit is contained in:
Stepland 2020-02-26 23:51:35 +01:00
parent d2194e9e00
commit c00db7d6f7
2 changed files with 7 additions and 1 deletions

View File

@ -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(

View File

@ -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;
};
}