Skip to content

Instantly share code, notes, and snippets.

@cdave1
Created April 13, 2014 00:21
Show Gist options
  • Save cdave1/10563386 to your computer and use it in GitHub Desktop.
Save cdave1/10563386 to your computer and use it in GitHub Desktop.

Revisions

  1. cdave1 created this gist Apr 13, 2014.
    32 changes: 32 additions & 0 deletions gistfile1.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #include "SDL2/SDL.h"
    #include "SDL2/SDL_mixer.h"

    static const char *MY_COOL_MP3 = "cool_tunes.mp3";

    int main(int argc, char **argv) {
    int result = 0;
    int flags = MIX_INIT_MP3;

    if (SDL_Init(SDL_INIT_AUDIO) < 0) {
    printf("Failed to init SDL\n");
    exit(1);
    }

    if (flags != (result = Mix_Init(flags))) {
    printf("Could not initialize mixer (result: %d).\n", result);
    printf("Mix_Init: %s\n", Mix_GetError());
    exit(1);
    }

    Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 640);
    Mix_Music *music = Mix_LoadMUS(MY_COOL_MP3);
    Mix_PlayMusic(music, 1);

    while (!SDL_QuitRequested()) {
    SDL_Delay(250);
    }

    Mix_FreeMusic(music);
    SDL_Quit();
    return 0;
    }