SDL_Mixer can't open wav

Started by
5 comments, last by Pacman18 8 years, 2 months ago

hi guys,

I've been following a tutorial on playing music in C++ with sdl_mixer, the program builds fine but when run I always get the error that the music couldn't load. I have copied test.wav into the project directory, is there something I am missing? Any help is appreciated


#include <iostream>
#include <SDL.h>
#include <SDL_mixer.h>
#include <stdio.h>
#include <string>


 Mix_Music *gMusic = NULL;

 Mix_Chunk *gScratch = NULL;
 Mix_Chunk *gHigh = NULL;
 Mix_Chunk *gMedium = NULL;
 Mix_Chunk *gLow = NULL;

bool loadMedia();


int main( int argc, char *argv[] )
{
    loadMedia();
    Mix_PlayMusic( gMusic, -1 );
    int a;
    std::cin >> a;
    return 0;
}

bool loadMedia()
{

     bool success = true;


     if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
     {
         printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
         success = false;
          }



      gMusic = Mix_LoadMUS( "test.wav" );
       if( gMusic == NULL )
        {
             printf( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() );
       success = false;
       }
}
Advertisement
To rule out you have not put the file in the wrong directory you could test passing the full path of the file to Mix_LoadMUS.

Nevermind, it works with mp3 which I prefer anyway

What does the error message say?

it kept saying the printf error - ( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() );

I tried an mp3 instead (which required I also put smpeg2.dll in the directory) and it worked, which as I say is better for me anyway

%s\n should be replaced by an actual error message from SDL_Mixer. What does that say?

Hello to all my stalkers.

sorry, it said "couldn't open test.wav"

This topic is closed to new replies.

Advertisement