Help with SDL_mixer (no sound)
- by Kaizoku
Hello,
I have this strange problem with SDL_mixer, it doesn't want to play music. It doesn't throw any error, it just skips it. Any advice? I am compiling on linux with libvorbis.
audio.h
#ifndef AUDIO_H
#define AUDIO_H
#include <string>
#include <SDL/SDL_mixer.h>
class Audio {
private:
Mix_Music *music;
public:
Audio();
virtual ~Audio();
public:
void setMusic(std::string path);
void playMusic();
};
#endif /* AUDIO_H */
audio.cpp
#include "Audio.h"
#include <stdexcept>
Audio::Audio() {
if (0 == Mix_Init(MIX_INIT_OGG))
throw std::runtime_error(Mix_GetError());
if (-1 == Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096))
throw std::runtime_error(Mix_GetError());
}
Audio::~Audio() {
Mix_FreeMusic(music);
Mix_Quit();
}
void Audio::setMusic(std::string path) {
music = Mix_LoadMUS(path.c_str());
if (NULL == music)
throw std::runtime_error(Mix_GetError());
}
void Audio::playMusic() {
if (NULL != music) {
if (-1 == Mix_PlayMusic(music, -1))
throw std::runtime_error(Mix_GetError());
}
}