Commit 3cd8525c authored by Ilya Prokhorov's avatar Ilya Prokhorov

Play music logic

parent b7cc0134
#include <FlameSteelBattleHorn/Sound.h>
#include <iostream>
using namespace FlameSteelGameToolkit::FlameSteelBattleHorn;
using namespace FlameSteelBattleHorn;
void Sound::initializeSoundSystem() {
#ifndef __EMSCRIPTEN__
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1 ) {
throw runtime_error("Can't initialize sound system");
}
int flags = MIX_INIT_OGG;
int initted = Mix_Init(flags);
cout << flags << endl;
cout << initted << endl;
if ((initted & flags) != flags) {
printf("Mix_Init: Failed to init required ogg and mod support!\n");
printf("Mix_Init: %s\n", Mix_GetError());
throw runtime_error("Can't initialize SDL_Mixer properly");
}
else {
cout << "SDL_MIXER initialized correctly" << endl;
}
#endif
}
Sound::Sound(shared_ptr<string> path) {
#ifndef __EMSCRIPTEN__
chunk = Mix_LoadWAV(path->c_str());
music = Mix_LoadMUS(path->c_str());
if (music == nullptr) {
cout << "Can't load music " << Mix_GetError() << endl;
throw runtime_error("Can't load music");
}
#endif
}
void Sound::play() {
#ifndef __EMSCRIPTEN__
if (chunk) {
}
if (music) {
if (Mix_PlayMusic(music, -1) == -1) {
throw runtime_error("Can't play music");
}
}
else {
throw runtime_error("Can't play music - music is null");
}
#endif
}
......
#ifndef FSBH_SOUND_H_
#define FSBH_SOUND_H_
#include <memory>
#include <string>
......@@ -9,12 +10,12 @@
using namespace std;
namespace FlameSteelGameToolkit {
namespace FlameSteelBattleHorn {
class Sound {
public:
static void initializeSoundSystem();
Sound(shared_ptr<string> path);
void play();
void stop();
......@@ -28,7 +29,6 @@ private:
};
}
}
#endif
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment