So from yesterday i am trying to play audio with this and it does not play:
//Opening according to web and youtube
Mix_Music* Hudba = Mix_LoadMUS(“Audio/Garage-theme.mp3”);
std::cout << “Chyba:” << Mix_GetError(); return 1;
Wav and mp3 are loading and found but not played. Do you know how to play them in c++? Do i have to play music in game loop or outside of game loop?
and also sorry if question sounds weird because its my first question on sdl
Did you call:
This is good practice in general, but Mix_OpenAudio() will call SDL_Init() for you if you forgot, so that’s not the problem in this case.
It’s not clear from the original post, but assuming there’s no loop in there, the @pavel5750cz might be thinking that Mix_PlayMusic blocks until the song completes; it does not, and the app needs to continue until the song is done playing.
If the program ends right after the call to Mix_PlayMusic, it won’t play anything.
I have loop inthere. And from what i understood is that i have to play kt outside. This is my first post so sorry for not enough info . Because of this i wanted to leabe sdl and switch to open gl
You should be able to start the music from anywhere in your program (assuming you have initialized SDL first).
OpenGL is a graphics API and has nothing to do with audio.
There is nothing preventing you from using OpenGL with SDL.
Also note that you should not free the
Mix_Music object using
Mix_FreeMusic until after you have finished playing the music otherwise it will stop the music.
i have it outside of loop and it looks like that and does not play :Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
Mix_Music* Hudba = Mix_LoadMUS("Audio/Garage-theme.mp3");
std::cout << "Chyba:" << Mix_GetError(); return 1;
So the program keeps running but without playing any music?
It would help if you posted a complete example program, with everything that is not relevant removed, but that can still be compiled and run to show the problem.