Jump to content
  • Advertisement
Sign in to follow this  
Pacman18

SDL_Mixer can't open wav

This topic is 996 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
       }
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!