-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoundManager.cpp
More file actions
78 lines (65 loc) · 1.57 KB
/
SoundManager.cpp
File metadata and controls
78 lines (65 loc) · 1.57 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "src/SoundManager.h"
SoundManager::SoundManager()
{
}
SoundManager& SoundManager::getInstance()
{
static SoundManager instance;
return instance;
}
void* play(void* name)
{
OggStream::getInstance();
char* songName;
songName = (char*) name;
bool valid = true;
while(valid) //continuosly loop background music
{
try
{
OggStream::getInstance().open(songName);
if(!OggStream::getInstance().playback())
throw std::string("Ogg Refused to Play");
while(OggStream::getInstance().update())
{
if(!OggStream::getInstance().playing())
{
if(!OggStream::getInstance().playback())
throw std::string("Ogg Stopped");
else
printf("Ogg Stream Interrupted\n");
}
}
}
catch(std::string error)
{
printf("DANGER ZONE\n");
printf("%s\n", error.c_str());
valid = false;
}
}
pthread_exit(NULL);
}
void SoundManager::close()
{
OggStream::getInstance().release();
}
void SoundManager::start(const char* title)
{
OggStream::getInstance();
int creation;
creation = pthread_create(&player, NULL, play, (void *) title);
if(creation)
{
printf("FAILED: Thread Creation\n");
}
}
void SoundManager::start(std::string title)
{
this->start(title.c_str());
}
void SoundManager::stop()
{
pthread_cancel(player);
OggStream::getInstance().stop();
}