#pragma once #include #include #include #include #include #include #include #include #include #include class AudioPlayerAsync { public: AudioPlayerAsync(); ~AudioPlayerAsync(); bool init(); void shutdown(); void playSoundAsync(const std::string& filePath, int loops = 0, int channel = -1); void playMusicAsync(const std::string& filePath, int loops = -1); void stopMusicAsync(); void pauseMusicAsync(); void resumeMusicAsync(); void setMusicVolume(int volume); // 0..128 void setSoundVolume(int volume); // 0..128 void exit() { stop = true; } private: void workerThread(); std::thread worker; std::mutex mtx; std::condition_variable cv; std::queue> taskQueue; bool stop = false; std::unordered_map soundCache; std::mutex soundCacheMutex; bool initialized = false; };