51 lines
1.2 KiB
C
51 lines
1.2 KiB
C
#include <SDL2/SDL.h>
|
|
#include <SDL2/SDL_mixer.h>
|
|
#include <SDL2/SDL_main.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int continuer = 1;
|
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
|
SDL_Event event;
|
|
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1) //Initialisation de l'API Mixer
|
|
{
|
|
printf("%s", Mix_GetError());
|
|
}
|
|
Mix_Music *musique; //Creation du pointeur de type Mix_Music
|
|
musique = Mix_LoadMUS("trigger.wav"); //Chargement de la musique
|
|
|
|
while(continuer)
|
|
{
|
|
SDL_WaitEvent(&event);
|
|
switch(event.type)
|
|
{
|
|
case SDL_KEYDOWN:
|
|
Mix_PlayMusic(musique, -1); //Jouer en boucle tant que la touche est enfoncee
|
|
SDL_WaitEvent(&event);
|
|
switch(event.type)
|
|
{
|
|
case SDL_KEYUP:
|
|
Mix_HaltMusic(); //Arreter la boucle si la touche est relachee
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
while(continuer)
|
|
{
|
|
SDL_WaitEvent(&event);
|
|
switch(event.type)
|
|
{
|
|
case SDL_QUIT:
|
|
continuer = 0;
|
|
break;
|
|
}
|
|
}
|
|
Mix_FreeMusic(musique); //Libération de la musique
|
|
Mix_CloseAudio(); //Fermeture de l'API
|
|
SDL_Quit();
|
|
return EXIT_SUCCESS;
|
|
}
|