diff --git a/src/Audio.c b/src/Audio.c index 540a331b2..4a93414a7 100644 --- a/src/Audio.c +++ b/src/Audio.c @@ -12,10 +12,13 @@ #include "Stream.h" #include "Utils.h" #include "Options.h" +#ifdef CC_BUILD_ANDROID +/* TODO: Refactor maybe to not rely on checking WinInfo.Handle != NULL */ +#include "Window.h" +#endif int Audio_SoundsVolume, Audio_MusicVolume; -/* TODO: Fix for android */ #if defined CC_BUILD_NOAUDIO /* Can't use mojang's sounds or music assets, so just stub everything out */ static void OnInit(void) { } @@ -960,6 +963,10 @@ static cc_result Music_PlayOgg(struct Stream* source) { if (res) goto cleanup; for (;;) { +#if 0 + /* Don't play music while in the background on Android */ + if (!WindowInfo.Handle && !music_pendingStop) { Thread_Sleep(10); continue; } +#endif next = -1; for (i = 0; i < AUDIO_MAX_BUFFERS; i++) { @@ -968,8 +975,8 @@ static cc_result Music_PlayOgg(struct Stream* source) { if (available) { next = i; break; } } - if (next == -1) { Thread_Sleep(10); continue; } if (music_pendingStop) break; + if (next == -1) { Thread_Sleep(10); continue; } res = Music_Buffer(next, &data[chunkSize * next], samplesPerSecond, &vorbis); /* need to specially handle last bit of audio */ diff --git a/src/Window.c b/src/Window.c index 664da54f5..0394b9c7e 100644 --- a/src/Window.c +++ b/src/Window.c @@ -3759,7 +3759,8 @@ static void JNICALL java_processMouseMove(JNIEnv* env, jobject o, jint id, jint static void JNICALL java_processSurfaceCreated(JNIEnv* env, jobject o, jobject surface) { Platform_LogConst("WIN - CREATED"); - win_handle = ANativeWindow_fromSurface(env, surface); + win_handle = ANativeWindow_fromSurface(env, surface); + WindowInfo.Handle = win_handle; RefreshWindowBounds(); /* TODO: Restore context */ Event_RaiseVoid(&WindowEvents.Created); @@ -3770,7 +3771,8 @@ static void JNICALL java_processSurfaceDestroyed(JNIEnv* env, jobject o) { Platform_LogConst("WIN - DESTROYED"); if (win_handle) ANativeWindow_release(win_handle); - win_handle = NULL; + win_handle = NULL; + WindowInfo.Handle = NULL; /* eglSwapBuffers might return EGL_BAD_SURFACE, EGL_BAD_ALLOC, or some other error */ /* Instead the context is lost here in a consistent manner */ if (Gfx.Created) Gfx_LoseContext("surface lost");