Posted by buergi on Fri 15th Jun 01:06
download | new post
- #include <SDL/SDL.h>
- #include <SDL/SDL_mixer.h>
- int main ( int argc, char** argv )
- {
- Mix_Music *music = NULL;
- // initialize SDL video
- if ( SDL_Init( SDL_INIT_AUDIO ) < 0 )
- {
- printf( "Unable to init SDL: %s\n", SDL_GetError() );
- return 1;
- }
- // make sure SDL cleans up before exit
- atexit(SDL_Quit);
- if(Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024)==-1) {
- printf( "Unable ot open audio device: %s\n", Mix_GetError() );
- return 2;
- }
- Mix_VolumeMusic(MIX_MAX_VOLUME/2);
- for (int i = 0;i<4;i++) {
- music = Mix_LoadMUS("tetris_theme.mp3");
- Mix_FadeInMusic(music, -1, 2000);
- //Mix_PlayMusic(music,0);
- SDL_Delay(3000);
- Mix_FadeOutMusic(2000);
- SDL_Delay(2000);
- Mix_HaltMusic();
- printf("free music\n");
- Mix_FreeMusic(music);
- printf("music freed\n");
- music = NULL;
- SDL_Delay(1000);
- }
- Mix_CloseAudio();
- return 0;
- }
Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.