diff --git a/src/guiengine/event_handler.cpp b/src/guiengine/event_handler.cpp index b812bae1e..53f5852dd 100644 --- a/src/guiengine/event_handler.cpp +++ b/src/guiengine/event_handler.cpp @@ -17,6 +17,8 @@ #include "guiengine/event_handler.hpp" +#include "audio/music_manager.hpp" +#include "audio/sfx_manager.hpp" #include "config/user_config.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/abstract_state_manager.hpp" @@ -39,6 +41,10 @@ #include +#ifdef ANDROID +#include +#endif + using GUIEngine::EventHandler; using GUIEngine::EventPropagation; @@ -148,6 +154,36 @@ bool EventHandler::OnEvent (const SEvent &event) { return onGUIEvent(event) == EVENT_BLOCK; } +#ifdef ANDROID + else if (event.EventType == EET_SYSTEM_EVENT && + event.SystemEvent.EventType == ESET_ANDROID_CMD) + { + int cmd = event.SystemEvent.AndroidCmd.Cmd; + + IrrlichtDevice* device = irr_driver->getDevice(); + assert(device != NULL); + + if (cmd == APP_CMD_PAUSE || cmd == APP_CMD_LOST_FOCUS) + { + // Make sure that pause/unpause is executed only once + if (device->isWindowMinimized() == device->isWindowFocused()) + { + music_manager->pauseMusic(); + SFXManager::get()->pauseAll(); + } + } + else if (cmd == APP_CMD_RESUME || cmd == APP_CMD_GAINED_FOCUS) + { + if (device->isWindowActive()) + { + music_manager->resumeMusic(); + SFXManager::get()->resumeAll(); + } + } + + return false; + } +#endif else if (GUIEngine::getStateManager()->getGameState() != GUIEngine::GAME && event.EventType != EET_KEY_INPUT_EVENT && event.EventType != EET_JOYSTICK_INPUT_EVENT && event.EventType != EET_LOG_TEXT_EVENT)