Do not exit if sound cannot be initialized.
This commit is contained in:
+10
-14
@@ -29,19 +29,15 @@ SDLPlayer::~SDLPlayer()
|
|||||||
void SDLPlayer::initAudio() {
|
void SDLPlayer::initAudio() {
|
||||||
|
|
||||||
audio_rate = 44100;
|
audio_rate = 44100;
|
||||||
audio_format = AUDIO_S16; /* 16-bit stereo */
|
audio_format = AUDIO_S16; /* 16-bit stereo */
|
||||||
audio_channels = 2;
|
audio_channels = 2;
|
||||||
audio_buffers = 4096;
|
audio_buffers = 4096;
|
||||||
music = NULL;
|
music = NULL;
|
||||||
|
|
||||||
SDL_Init(SDL_INIT_AUDIO);
|
SDL_Init(SDL_INIT_AUDIO);
|
||||||
|
|
||||||
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
|
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) == 0)
|
||||||
printf("Unable to open audio!\n");
|
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLPlayer::playSound(string audioString) {
|
void SDLPlayer::playSound(string audioString) {
|
||||||
@@ -52,7 +48,7 @@ void SDLPlayer::playSound(string audioString) {
|
|||||||
/* Actually loads up the music */
|
/* Actually loads up the music */
|
||||||
string completeAudioString = audioString + ".wav";
|
string completeAudioString = audioString + ".wav";
|
||||||
music = Mix_LoadMUS(completeAudioString.c_str());
|
music = Mix_LoadMUS(completeAudioString.c_str());
|
||||||
|
|
||||||
/* This begins playing the music - the first argument is a
|
/* This begins playing the music - the first argument is a
|
||||||
pointer to Mix_Music structure, and the second is how many
|
pointer to Mix_Music structure, and the second is how many
|
||||||
times you want it to loop (use -1 for infinite, and 0 to
|
times you want it to loop (use -1 for infinite, and 0 to
|
||||||
@@ -70,15 +66,15 @@ void SDLPlayer::playSound(string audioString) {
|
|||||||
void SDLPlayer::audioDone() {
|
void SDLPlayer::audioDone() {
|
||||||
|
|
||||||
Mix_HaltMusic();
|
Mix_HaltMusic();
|
||||||
Mix_FreeMusic(music);
|
Mix_FreeMusic(music);
|
||||||
music = NULL;
|
music = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLPlayer::closeAudio() {
|
void SDLPlayer::closeAudio() {
|
||||||
|
|
||||||
Mix_HaltMusic();
|
Mix_HaltMusic();
|
||||||
Mix_FreeMusic(music);
|
Mix_FreeMusic(music);
|
||||||
music = NULL;
|
music = NULL;
|
||||||
Mix_CloseAudio();
|
Mix_CloseAudio();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user