// This is a simple music player that demonstrates the SDL Mixer API // in a 'C' context. To build the program, use: // // cc -o sdlmixplay sdlmixplay.c -lSDL -lSDL_mixer #include #include Mix_Music *music = NULL; int phaserChannel = -1; int main (int argc, char **argv) { SDL_Surface *screen; SDL_Event event; int done = 0; if (argc != 2) { puts ("Usage: sdlmixplay FILE"); puts ("\nFILE may be of any type supported by the SDL Mixer"); exit (1); } SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO); if (Mix_OpenAudio (44100, MIX_DEFAULT_FORMAT, 2, 4096)) { printf ("Error initializing SDL_mixer: %s\n", Mix_GetError()); exit (1); } music = Mix_LoadMUS (argv [1]); if (!music) { printf ("Mix_LoadMus error:%s\n", Mix_GetError()); exit (1); } Mix_PlayMusic (music, 0); screen = SDL_SetVideoMode (320, 240, 0, 0); while (!done) { while (SDL_PollEvent (&event)) { switch (event.type) { case SDL_QUIT: done = 1; break; } } SDL_Delay (10); } Mix_FreeMusic (music); Mix_CloseAudio(); SDL_Quit(); exit (0); }