SDL2_mixer-2.0.2: resumeMusic causes Android app to hang?

When I was using SDL-2.0.5 and SDL_mixer 2.0.0, things worked well, but I needed some changes that were in a new version of the libraries, so I updated to SDL2-2.0.8 with SDL_mixer 2.0.2 with OGG support, and now the app hangs when it comes back into focus and resumes playing music. I was hoping to see if anyone had an idea of what I might be doing wrong before I file a bug report.

Everything builds fine using the NDK, and I can deploy to my Android device (Samsung Galaxy S7).

When I switch to a different app, my logs show that my event handler does handle SDL_APP_WILLENTERBACKGROUND by pausing the music using Mix_PauseMusic().

When I bring the app back up, my logs show that the event handler does handle SDL_APP_DIDENTERFOREGROUND, where I call Mix_ResumeMusic().

My logs show that once the call to Mix_ResumeMusic occurs, the app hangs (even switching apps again does not show any more logs going through the event handler) until Android says that the app is not responding and asks me to close it or wait.

Before I updated the library versions, I found that if I didn’t pause the music before the app entered the background, it would cause problems (I believe it crashed or would hang, but I don’t remember), but I am at a loss as to why resuming when the app is coming back into the foreground would cause an issue.

If I remove the call to Mix_ResumeMusic(), the app runs just fine, except there is a lack of music of course. Sound effects play just fine.

If I remove the call to Mix_PauseMusic(), the app hangs upon calling resume.

My investigation so far has pointed me to Mix_ResumeMusic() not working correctly on Android, but I wonder if there is something else I need to do perhaps to suspend or resume correctly? The only things I do are pause music and resume music, and maybe something else needs to be done, such as ensuring an open audio device or something like that?

I finally had some time to dig into this issue some more. The way I resolved it was to allow SDL_APP_DIDENTERFOREGROUND to pass out of the event filter into the main event loop, and when I handle the event there, I call Mix_ResumeMusic().

I assume there must have been some threading issue, but I still don’t know exactly what went wrong. So I can pause music in the event filter as the app is entering the background, but I can’t unpause in the event filter when the app has entered the foreground. I have to unpause when I am in the main event loop.

In my investigations, I also learned that it is not possible to call Mix_PausedMusic() in the event filter when handling the SDL_APP_WILLENTERBACKGROUND event, as it seems to hang there as well. Again, I presume it is a threading issue.