Last active
June 16, 2017 04:18
-
-
Save jamiltron/ce20bb233f3ec11a2fad598361656975 to your computer and use it in GitHub Desktop.
sdl_mixer_ogg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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