-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioManager.cpp
More file actions
60 lines (51 loc) · 1.59 KB
/
AudioManager.cpp
File metadata and controls
60 lines (51 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "AudioManager.h"
// Default constructor
AudioManager::AudioManager() {}
// Play music from the provided file path
void AudioManager::playMusic(const std::string& filePath, bool loop, float volume) {
if (!currentMusic.openFromFile(filePath)) {
std::cerr << "Error loading music: " << filePath << std::endl;
return;
}
currentMusic.setLoop(loop);
currentMusic.setVolume(volume);
currentMusic.play();
}
// Play jumpscare sound effect
void AudioManager::playJumpscareSound(const std::string& filePath, float volume) {
if (!jumpscareBuffer.loadFromFile(filePath)) {
std::cerr << "Error loading jumpscare sound: " << filePath << std::endl;
return;
}
jumpscareSound.setBuffer(jumpscareBuffer);
jumpscareSound.setVolume(volume);
jumpscareSound.play();
}
// Stop the currently playing music
void AudioManager::stopMusic() {
currentMusic.stop();
}
// Stop jumpscare sound
void AudioManager::stopJumpscareSound() {
jumpscareSound.stop();
}
// Change the volume of the music
void AudioManager::setVolume(float volume) {
currentMusic.setVolume(volume);
}
// Method to enqueue music tracks
void AudioManager::enqueueTrack(const std::string& track) {
musicQueue.enqueue(track);
}
// Play the next track in the queue
void AudioManager::playNextTrack() {
if (!musicQueue.isEmpty()) {
std::string nextTrack = musicQueue.dequeue();
playMusic(nextTrack); // Play the dequeued track
}
else {
std::cout << "No more tracks in the queue." << std::endl;
}
}
// Destructor
AudioManager::~AudioManager() {}