Hi, what I want to do is load in an .ogg file at startup and play it right away, but it doesn’t begin playing the audio at exactly the beginning, more like 1 or 2 seconds in. It’s almost as if either Mix_OpenAudio or Mix_LoadMUS takes 1 or 2 seconds to finish its job but meanwhile the Mix_PlayMusic started before and when it can actually play the audio it thinks it’s 1 or 2 seconds into the song, but that’s just my guess. Here’s my source:
Code:
int main(int argc, char* args[])
{
int state = 1;
SDL_Surface* screen = NULL;
Mix_Music *bgm = NULL;
SDL_Init(SDL_INIT_EVERYTHING);
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
bgm = Mix_LoadMUS("bgm.ogg");
screen = SDL_SetVideoMode(640, 480, 24, SDL_SWSURFACE);
//SDL_Delay(1000);
Mix_PlayMusic(bgm, 0);
while(state && SDL_WaitEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
state = 0;
Mix_HaltMusic();
Mix_FreeMusic(bgm);
Mix_CloseAudio();
SDL_Quit();
break;
default:
break;
}
}
return 0;
}
If the SDL_Delay(1000); is uncommented above, the music will play exactly at the start, but I don’t want it to delay. I have tried loading .mp3 and .wav files to no avail. So my question is, is there any way I can get it to play correctly as soon as possible without calling SDL_Delay()?