Skip to content

Instantly share code, notes, and snippets.

@jamiltron
Last active June 16, 2017 04:18
Show Gist options
  • Save jamiltron/ce20bb233f3ec11a2fad598361656975 to your computer and use it in GitHub Desktop.
Save jamiltron/ce20bb233f3ec11a2fad598361656975 to your computer and use it in GitHub Desktop.
sdl_mixer_ogg
#include <SDL.h>
#include <SDL_mixer.h>
#include <string>
#include <iostream>
Mix_Music *music = nullptr;
int main(int argc, char* argv[]) {
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
return -1;
}
if( Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1) {
return -1;
}
std::cout << "loading..." << std::endl;
music = Mix_LoadMUS("./hangs_forever.ogg");
if (music == nullptr) {
return -1;
}
std::cout << "playing..." << std::endl;
if (Mix_PlayMusic(music, -1) == -1) {
return -1;
}
while (Mix_PlayingMusic())
;
std::cout << "done playing!" << std::endl;
Mix_FreeMusic(music);
Mix_CloseAudio();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment