#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <stdio.h>
#include <stdlib.h>
Mix_Music *play_sound = NULL;
void cleanUp();
int main(int argc, char* args[])
{
int channel;
int audio_rate;
Uint16 audio_format;
int audio_channels;
int audio_buffers;
if(SDL_Init(SDL_INIT_AUDIO)<0)
printf("Error In Init");
audio_rate = 44100;
audio_format = AUDIO_S16;
audio_channels = 2;
audio_buffers = 4096;
if(Mix_OpenAudio(audio_rate, audio_format, 2, 4096)<0) {
//Some error shows here
} else {
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
printf("Opened audio at %d Hz %d bit %s (%s), %d bytes audio buffer\n", audio_rate,
(audio_format&0xFF),
(audio_channels > 2) ? "surround" : (audio_channels > 1) ? "stereo" : "mono",
(audio_format&0x1000) ? "BE" : "LE",
audio_buffers );
}
play_sound = Mix_LoadMUS("1.mp3");
if ( play_sound == NULL ) {
fprintf(stderr, "Couldn't load 1.mp3: %s\n",
SDL_GetError());
cleanUp();
return;
}
Mix_PlayMusic(play_sound, -1);
while (Mix_PlayingMusic() || Mix_PausedMusic()) {
SDL_Delay(100);
}
cleanUp();
return 0;
}
void cleanUp()
{
Mix_FreeMusic(play_sound);
Mix_CloseAudio();
SDL_Quit();
}
这是我的输出:
Opened audio at 44100 Hz 16 bit stereo (LE), 4096 bytes audio buffer
Couldn't load 1.mp3: Unrecognised music format
谁能告诉我播放 mp3 文件有什么问题SDL
?