[Android] Fixes #2480, music does not pause when process backgrounded
This modifies SDL_PauseAudio behavior to pause all audio devices instead of just the default one (required on Android, at least for testmultiaudio on my Nexus 4 which reported 2 audio devices). It also changes SDL_PauseAudioDevice to retain the device lock from pause until resume in order to save battery in mobile devices.
This commit is contained in:
parent
b70d45cec5
commit
8a4dc0573c
3 changed files with 30 additions and 6 deletions
|
@ -1348,17 +1348,26 @@ void
|
|||
SDL_PauseAudioDevice(SDL_AudioDeviceID devid, int pause_on)
|
||||
{
|
||||
SDL_AudioDevice *device = get_audio_device(devid);
|
||||
if (device) {
|
||||
current_audio.impl.LockDevice(device);
|
||||
if (device && device->paused != pause_on) {
|
||||
if (pause_on) {
|
||||
current_audio.impl.LockDevice(device);
|
||||
}
|
||||
device->paused = pause_on;
|
||||
current_audio.impl.UnlockDevice(device);
|
||||
if (!pause_on) {
|
||||
current_audio.impl.UnlockDevice(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_PauseAudio(int pause_on)
|
||||
{
|
||||
SDL_PauseAudioDevice(1, pause_on);
|
||||
int id;
|
||||
for (id = 0; id < SDL_arraysize(open_devices); id++) {
|
||||
if (open_devices[id] != NULL) {
|
||||
SDL_PauseAudioDevice(id+1, pause_on);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -74,13 +74,14 @@ Android_PumpEvents(_THIS)
|
|||
if (isPaused && !isPausing) {
|
||||
/* Make sure this is the last thing we do before pausing */
|
||||
android_egl_context_backup();
|
||||
SDL_PauseAudio(1);
|
||||
if(SDL_SemWait(Android_ResumeSem) == 0) {
|
||||
#else
|
||||
if (isPaused) {
|
||||
if(SDL_SemTryWait(Android_ResumeSem) == 0) {
|
||||
#endif
|
||||
isPaused = 0;
|
||||
|
||||
SDL_PauseAudio(0);
|
||||
/* Restore the GL Context from here, as this operation is thread dependent */
|
||||
if (!SDL_HasEvent(SDL_QUIT)) {
|
||||
android_egl_context_restore();
|
||||
|
@ -103,6 +104,7 @@ Android_PumpEvents(_THIS)
|
|||
#else
|
||||
if(SDL_SemTryWait(Android_PauseSem) == 0) {
|
||||
android_egl_context_backup();
|
||||
SDL_PauseAudio(1);
|
||||
isPaused = 1;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue