Fixed audio on android to properly pause when the app is inactive, and resume when the app becomes active again.

This commit is contained in:
Alex Szpakowski
2016-01-31 18:41:24 -04:00
parent 588013727c
commit c2de8dbb6a
+15 -16
View File
@@ -510,22 +510,6 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
msg = new Message("joystickremoved", vargs);
}
break;
#ifdef LOVE_ANDROID
case SDL_WINDOWEVENT_MINIMIZED:
{
auto audio = Module::getInstance<audio::Audio>(Module::M_AUDIO);
if (audio)
audio->pause();
}
break;
case SDL_WINDOWEVENT_RESTORED:
{
auto audio = Module::getInstance<audio::Audio>(Module::M_AUDIO);
if (audio)
audio->resume();
}
break;
#endif
default:
break;
}
@@ -590,6 +574,21 @@ Message *Event::convertWindowEvent(const SDL_Event &e) const
if (win)
win->onSizeChanged(e.window.data1, e.window.data2);
break;
case SDL_WINDOWEVENT_MINIMIZED:
case SDL_WINDOWEVENT_RESTORED:
#ifdef LOVE_ANDROID
{
auto audio = Module::getInstance<audio::Audio>(Module::M_AUDIO);
if (audio)
{
if (e.window.event == SDL_WINDOWEVENT_MINIMIZED)
audio->pause();
else if (e.window.event == SDL_WINDOWEVENT_RESTORED)
audio->resume();
}
}
#endif
break;
}
// We gave +1 refs to the StrongRef list, so we should release them.