Advertisement
ProToTN

How to add music on SDL

Feb 16th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1.  { 
  2.     Mix_Music *musicc;
  3.     Mix_Chunk *ding;
  4.     int continuer=1;
  5.    
  6.     if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1)
  7.     {
  8.         fprintf(stderr,"%s", Mix_GetError());
  9.     }
  10.  
  11.  
  12.     ding = Mix_LoadWAV("Fail.wav");
  13.     musicc = Mix_LoadMUS("sound.mp3");
  14.     Mix_PlayMusic(musicc, -1);
  15.  
  16.  
  17.  
  18.     while(continuer==1)
  19.     {
  20.         SDL_PollEvent(&event);
  21.         switch(event.type)
  22.         {
  23.             case SDL_QUIT:
  24.             continuer=0;
  25.             break;
  26.             case SDL_MOUSEBUTTONUP:
  27.             if(((event.button.x>314)&&(event.button.x<489))&&((event.button.y>404)&&(event.button.y<438)))
  28.             Mix_PlayChannel(-1, ding, 0);
  29.  
  30.             else if(((event.button.x>342)&&(event.button.x<457))&&((event.button.y>453)&&(event.button.y<483)))
  31.             Mix_PlayChannel(-1, ding, 0);
  32.  
  33.             else if(((event.button.x>343)&&(event.button.x<454))&&((event.button.y>494)&&(event.button.y<526)))
  34.             Mix_PlayChannel(-1, ding, 0);
  35.  
  36.             else if(((event.button.x>359)&&(event.button.x<439))&&((event.button.y>537)&&(event.button.y<573)))
  37.             {
  38.                 Mix_PlayChannel(-1, ding, 0);
  39.                 continuer=0;
  40.             }
  41.             break;
  42.         }  
  43.     }
  44.  
  45.  
  46.  
  47.  
  48.     Mix_FreeChunk(ding);
  49.     Mix_FreeMusic(musicc);
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement