Steward
分享是一種喜悅、更是一種幸福
程式語言 - Simple DirectMedia Layer (SDL) - v2.0 - C/C++ - Load Music
參考資訊:
https://wiki.libsdl.org/FrontPage
main.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <stdio.h> #include <stdlib.h> #include <SDL.h> #include <SDL_mixer.h> int main ( int argc, char **argv) { const int w = 320; const int h = 240; const int bpp = 16; SDL_Window * window = NULL ; SDL_Renderer *renderer = NULL ; SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_AUDIO ); window = SDL_CreateWindow ( "main" , SDL_WINDOWPOS_UNDEFINED , SDL_WINDOWPOS_UNDEFINED , w, h, SDL_WINDOW_SHOWN ); renderer = SDL_CreateRenderer ( window , -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ); SDL_RenderClear (renderer); SDL_RenderPresent (renderer); Mix_OpenAudio (44100, MIX_DEFAULT_FORMAT , 2, 4096); Mix_Music *music = Mix_LoadMUS ( "main.wav" ); Mix_PlayMusic (music, 1); SDL_Delay (3000); Mix_HaltMusic (); Mix_FreeMusic (music); Mix_CloseAudio (); SDL_DestroyRenderer (renderer); SDL_DestroyWindow ( window ); SDL_Quit (); return 0; } |
P.S. 支援WAVE, MOD, MIDI, OGG, MP3, FLAC
編譯
$ gcc main.c -o main -lSDL2 -lSDL2_mixer -I/usr/include/SDL2