在我的一个小项目上工作,我打算合并一些音乐文件...... 刚刚发现SDL,并认为这将是一个完美的匹配,因为我打算使用.ogg文件。 然而......当我尝试加载.ogg文件时... Mix_LoadMUS总是返回NULL ...不知道为什么......
截至目前我的代码:
int flags = MIX_INIT_OGG | MIX_INIT_MOD;
int initted = Mix_Init(flags);
// start SDL with audio support
if (SDL_Init(SDL_INIT_AUDIO) == -1) {
printf("SDL_Init: %s\n", SDL_GetError());
exit(1);
}
if (initted&flags != flags) {
printf("Mix_Init: Failed to init required ogg and mod support!\n");
printf("Mix_Init: %s\n", Mix_GetError());
// handle error
}
// open 44.1KHz, signed 16bit, system byte order,
// stereo audio, using 1024 byte chunks
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1) {
printf("Mix_OpenAudio: %s\n", Mix_GetError());
exit(2);
}
printf("There are %d sample chunk deocoders available\n", Mix_GetNumChunkDecoders());
printf("There are %d music deocoders available\n", Mix_GetNumMusicDecoders());
// print music decoders available
int i, max = Mix_GetNumMusicDecoders();
for (i = 0; i<max; ++i)
printf("Music decoder %d is for %s\n",i, Mix_GetMusicDecoder(i));
Mix_Music *BackgroundMusic;
BackgroundMusic = Mix_LoadMUS("sounds/Main_Theme.ogg");
if (BackgroundMusic == NULL) {
printf("Unable to load Ogg file: %s\n", Mix_GetError());
return 1;
}
我做错了什么?