Browse Source

Pause OpenAL when the app is in the background, on Android.

Martin Felis 10 years ago
parent
commit
637a3a9d62

+ 6 - 0
src/modules/audio/openal/Audio.cpp

@@ -190,6 +190,9 @@ void Audio::pause(love::audio::Source *source)
 void Audio::pause()
 {
 	pool->pause();
+#ifdef LOVE_ANDROID
+	alcDevicePauseSOFT(device);
+#endif
 }
 
 void Audio::resume(love::audio::Source *source)
@@ -199,6 +202,9 @@ void Audio::resume(love::audio::Source *source)
 
 void Audio::resume()
 {
+#ifdef LOVE_ANDROID
+	alcDeviceResumeSOFT(device);
+#endif
 	pool->resume();
 }
 

+ 1 - 0
src/modules/audio/openal/Audio.h

@@ -47,6 +47,7 @@
 #else
 #include <AL/alc.h>
 #include <AL/al.h>
+#include <AL/alext.h>
 #endif
 
 namespace love

+ 21 - 0
src/modules/event/sdl/Event.cpp

@@ -29,6 +29,7 @@
 #include "graphics/Graphics.h"
 #include "window/Window.h"
 #include "common/Exception.h"
+#include "audio/Audio.h"
 #include "common/config.h"
 
 #include <cmath>
@@ -509,6 +510,22 @@ 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;
 	}
@@ -802,6 +819,10 @@ std::map<SDL_Keycode, love::keyboard::Keyboard::Key> Event::createKeyMap()
 	k[SDLK_EJECT] = Keyboard::KEY_EJECT;
 	k[SDLK_SLEEP] = Keyboard::KEY_SLEEP;
 
+#ifdef LOVE_ANDROID
+	k[SDLK_AC_BACK] = Keyboard::KEY_ESCAPE;
+#endif
+
 	return k;
 }