Music not playing SDL

Hi,

I have a problem, the music that I want to plays not run :( Theoretically all arguments are well, but I don't understand why not works. I have all libraries installed, good ... So somebody know what happens? Thanks

1
2
3
4
5
6
7
8
9
10
11
12
      if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) < 0) {
      cout << "Error inesperado";
      return 0;
   }
        Mix_Init(0);
        Mix_Music *musica = NULL;
        musica = Mix_LoadMUS("pixeluniverse.wav");
   if (!Mix_PlayMusic(musica, -1)) {
      cout << "Error inesperado";
   }

...

Make sure that Mix_LoadMUS does not return NULL.

EDIT: Mix_PlayMusic returns -1 on error and 0 otherwise so your second if statement will print "Error inesperado" only if there was no error.
Last edited on
Thanks for replying so fast!

Mmm I change it for :

1
2
3
4
5
6
7
8
9
10
if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) < 0) {
      cout << "Error inesperado";
      return 0;
   }
        Mix_Init(0);
        Mix_Music *musica = 0;
        musica = Mix_LoadMUS("pixeluniverse.wav");
   if (Mix_PlayMusic(musica, -1) < 0) {
      cout << "Error inesperado";
   }


And now, the terminal says "Error inesperado" because it can't play the music... But WHY??

I have installed the Mixer libraries and the music file exist. And I think the source are correct, right?
Maybe not works because the WAV have a lot of MB?? ; 8,4 MB

Thanks :D ;
Puntoinfinito
Put this between line 7-8 and see what error message you get.
1
2
3
if(musica == NULL) {
	cout << Mix_GetError() << std::endl;;
}

Why are you calling Mix_Init after you attempt to open a device?

Shouldn't Mix_Init be the very first thing you call?
Last edited on
Peter87, program otput ; "Unable to load WAV file".. Why?

Disch, ye thx, it fixed :)
Last edited on
Ok so that should mean that the file is being loaded correctly. Print the return value of Mix_GetError() where you are printing "Error inesperado" and it will probably tell you what is wrong.
Last edited on
@Peter87

Output: "music parameter was NULL" ... TT

Why?!
Last edited on
Mix_LoadMUS failed, because it was
Unable to load WAV file

Can you play it in external audio players?

It looks a good WAV file because it's heavy, most WAV files are heavy.
Last edited on
Nop, I can't. The problem is that the WAV file are so heavy?
Yes that's the problem :/

I try with another music (just 800kb) and it works... Not there a solution.. I need that file
I don't think that a big file is a problem. Try re-encoding it to WAV.
Yes!! That was the problem :/ Now it worksss thx a lot all!!
Topic archived. No new replies allowed.