I can't understand why my program doesn't sound anything. I think it should work because I've almost copied the code from here. As you can se I use SDL Mixer.
Code:
#include "SDL.h"
#include "SDL_mixer.h"
bool init();
bool load_files();
void clean_up();
Mix_Music *music = NULL;
SDL_Surface *screen = NULL;
SDL_Event event;
int main(int argc, char *argv[])
{
bool quit = false;
if (init() == false)
return 1;
if (load_files() == false)
return 1;
while (quit == false)
{
while (SDL_PollEvent(&event))
{
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_SPACE) {
if (Mix_PlayingMusic == 0) {
if (Mix_PlayMusic(music, -1) == -1)
return 1;
} else {
if (Mix_PausedMusic() == 1)
Mix_ResumeMusic();
else
Mix_PauseMusic();
}
} else if (event.key.keysym.sym == SDLK_ESCAPE) {
Mix_HaltMusic();
}
} else if (event.type == SDL_QUIT) {
quit = true;
}
}
}
clean_up();
return 0;
}
bool init()
{
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) == -1)
return false;
screen = SDL_SetVideoMode(320, 240, 0, 0);
if (screen == NULL)
return false;
if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1)
return false;
SDL_WM_SetCaption("Musicplayer", NULL);
return true;
}
bool load_files()
{
music = Mix_LoadMUS("test.mp3");
if (music == NULL)
return false;
return true;
}
void clean_up()
{
Mix_FreeMusic(music);
Mix_CloseAudio();
SDL_Quit();
}