-
How to auto exit when finished? I tried this code by removing getchar but it doesn't work if you add getchar, but it doesn't auto exit #define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"
#include <stdio.h>
void play(char* path)
{
ma_result result;
ma_engine engine;
result = ma_engine_init(NULL, &engine);
if (result != MA_SUCCESS) {
printf("Failed to initialize audio engine.");
}
ma_engine_play_sound(&engine, path, NULL);
ma_engine_uninit(&engine);
exit(0);
} Sorry I'm still a beginner in c |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Can you explain in more detail what it is you're trying to achieve? Do you want to just play a sound and then exit the whole program when the sound finishes playing? If so, you need to periodically call |
Beta Was this translation helpful? Give feedback.
-
I also tried to make a music player on top of miniaudio a while ago! Here's the code for reference, maybe it can help you get some ideas: https://github.com/joshnatis/winona. It's pretty hacky and I don't think it's a great example, but it works. I solved the "when's the song over?" problem by doing basically what mackron suggested, periodically checking if the # of frames read is 0, and if so moving on to the next song. Also note that it's using an old version of miniaudio so some things may be deprecated by now, and that it's using the low level API. |
Beta Was this translation helpful? Give feedback.
Can you explain in more detail what it is you're trying to achieve? Do you want to just play a sound and then exit the whole program when the sound finishes playing? If so, you need to periodically call
ma_sound_at_end()
to know when the sound has finished, but you won't be able to usema_engine_play_sound()
for that because it doesn't give you ama_sound
object. Instead you'll need to initialize a soundma_sound
object withma_sound_init_from_file()
. There's no way to wait forma_engine_play_sound()
to finish - that function plays the sound asynchronously (it returns straight away while the sound plays in the background).