Fix automatically pausing and resuming audio on android (resolves #1237)

--HG--
branch : minor
This commit is contained in:
Bart van Strien
2016-12-02 13:59:21 +01:00
parent 67d3146229
commit cac5a3519a
2 changed files with 23 additions and 10 deletions
+16 -8
View File
@@ -164,7 +164,7 @@ void Event::exceptionIfInRenderPass()
throw love::Exception("Cannot call this function while a render pass is active in love.graphics."); throw love::Exception("Cannot call this function while a render pass is active in love.graphics.");
} }
Message *Event::convert(const SDL_Event &e) const Message *Event::convert(const SDL_Event &e)
{ {
Message *msg = nullptr; Message *msg = nullptr;
@@ -528,7 +528,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
return msg; return msg;
} }
Message *Event::convertWindowEvent(const SDL_Event &e) const Message *Event::convertWindowEvent(const SDL_Event &e)
{ {
Message *msg = nullptr; Message *msg = nullptr;
@@ -581,16 +581,24 @@ Message *Event::convertWindowEvent(const SDL_Event &e) const
case SDL_WINDOWEVENT_MINIMIZED: case SDL_WINDOWEVENT_MINIMIZED:
case SDL_WINDOWEVENT_RESTORED: case SDL_WINDOWEVENT_RESTORED:
#ifdef LOVE_ANDROID #ifdef LOVE_ANDROID
{ if (auto audio = Module::getInstance<audio::Audio>(Module::M_AUDIO))
auto audio = Module::getInstance<audio::Audio>(Module::M_AUDIO);
if (audio)
{ {
if (e.window.event == SDL_WINDOWEVENT_MINIMIZED) if (e.window.event == SDL_WINDOWEVENT_MINIMIZED)
audio->pause(); {
for (auto &src : pausedSources)
src->release();
pausedSources = audio->pause();
for (auto &src : pausedSources)
src->retain();
}
else if (e.window.event == SDL_WINDOWEVENT_RESTORED) else if (e.window.event == SDL_WINDOWEVENT_RESTORED)
audio->resume(); {
audio->play(pausedSources);
for (auto &src : pausedSources)
src->release();
pausedSources.resize(0);
}
} }
}
#endif #endif
break; break;
} }
+7 -2
View File
@@ -23,6 +23,7 @@
// LOVE // LOVE
#include "event/Event.h" #include "event/Event.h"
#include "audio/Source.h"
// SDL // SDL
#include <SDL_events.h> #include <SDL_events.h>
@@ -70,13 +71,17 @@ private:
void exceptionIfInRenderPass(); void exceptionIfInRenderPass();
Message *convert(const SDL_Event &e) const; Message *convert(const SDL_Event &e);
Message *convertJoystickEvent(const SDL_Event &e) const; Message *convertJoystickEvent(const SDL_Event &e) const;
Message *convertWindowEvent(const SDL_Event &e) const; Message *convertWindowEvent(const SDL_Event &e);
static std::map<SDL_Keycode, love::keyboard::Keyboard::Key> createKeyMap(); static std::map<SDL_Keycode, love::keyboard::Keyboard::Key> createKeyMap();
static std::map<SDL_Keycode, love::keyboard::Keyboard::Key> keys; static std::map<SDL_Keycode, love::keyboard::Keyboard::Key> keys;
#ifdef LOVE_ANDROID
std::vector<love::audio::Source*> pausedSources;
#endif
}; // Event }; // Event
} // sdl } // sdl