Minor refactoring
This commit is contained in:
1 parent
0a5a3b653d
commit
592e008914
43 files changed
+3589
-3594
No files matched your search
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef AUDIO
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <queue>
|
||||
#include <functional>
|
||||
#include "cmakeaudioplayer/include/AudioPlayer.hpp"
|
||||
|
||||
|
||||
class AudioPlayerAsync {
|
||||
public:
|
||||
AudioPlayerAsync();
|
||||
~AudioPlayerAsync();
|
||||
|
||||
void resetAsync();
|
||||
|
||||
void playSoundAsync(std::string soundName);
|
||||
|
||||
void playMusicAsync(std::string musicName);
|
||||
|
||||
void stopAsync();
|
||||
|
||||
void exit()
|
||||
{
|
||||
stop = true;
|
||||
}
|
||||
|
||||
std::thread worker;
|
||||
|
||||
private:
|
||||
std::unique_ptr<AudioPlayer> audioPlayer;
|
||||
//std::mutex audioPlayerMutex;
|
||||
|
||||
std::mutex soundNameMutex;
|
||||
std::mutex musicNameMutex;
|
||||
|
||||
std::string latestSoundName;
|
||||
std::string latestMusicName;
|
||||
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
std::queue<std::function<void()>> taskQueue;
|
||||
bool stop = false;
|
||||
|
||||
void workerThread();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user