# SDL2\_mixer-2.0.2: resumeMusic causes Android app to hang?

**URL:** <https://discourse.libsdl.org/t/sdl2-mixer-2-0-2-resumemusic-causes-android-app-to-hang/24856>\
**Category:** SDL Development\
**Created:** [August 16, 2018, 3:52am UTC](https://discourse.libsdl.org/t/sdl2-mixer-2-0-2-resumemusic-causes-android-app-to-hang/24856 "2018-08-16T03:52:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gianfranco\_Berardi](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/gianfranco_berardi/32/478_2.png) [@Gianfranco\_Berardi](https://discourse.libsdl.org/u/Gianfranco_Berardi)\
**Post date:** [August 16, 2018, 3:52am UTC](https://discourse.libsdl.org/t/sdl2-mixer-2-0-2-resumemusic-causes-android-app-to-hang/24856/1 "2018-08-16T03:52:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Gianfranco\_Berardi](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/gianfranco_berardi/32/478_2.png) [@Gianfranco\_Berardi](https://discourse.libsdl.org/u/Gianfranco_Berardi)\
**Post date:** [November 26, 2018, 5:46pm UTC](https://discourse.libsdl.org/t/sdl2-mixer-2-0-2-resumemusic-causes-android-app-to-hang/24856/2 "2018-11-26T17:46:47Z")

</div>

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.
