改进RDAudio::pause(),优化Android下暂停的性能损耗。同时修正Java编译错误。

This commit is contained in:
u0u0
2020-07-06 21:20:16 +08:00
parent 7be0d10bc2
commit cdaf7db995
5 changed files with 25 additions and 10 deletions

View File

@@ -67,18 +67,16 @@ void RDAudio::destroyInstance()
void RDAudio::pause()
{
//#if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID
alcMakeContextCurrent(NULL);
alcSuspendContext(_context);
//#endif
if (_device) {
alcDevicePauseSOFT(_device);
}
}
void RDAudio::resume()
{
//#if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID
alcMakeContextCurrent(_context);
alcProcessContext(_context);
//#endif
if (_device) {
alcDeviceResumeSOFT(_device);
}
}
void RDAudio::waitForQuit()

View File

@@ -24,6 +24,7 @@
#include "platform/CCPlatformConfig.h"
#include "base/CCRef.h"
#define AL_ALEXT_PROTOTYPES
#include "alext.h"
typedef void (*AudioCallback)(int funcID, ALuint bufferID);

View File

@@ -53,6 +53,8 @@ import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener;
import org.cocos2dx.utils.PSNetwork;
import org.cocos2dx.utils.PSDevice;
import java.util.ArrayList;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;

View File

@@ -78,6 +78,18 @@ static int lnewSource(lua_State * L)
return 1;// number of return values
}
static int lpause(lua_State * L)
{
RDAudio::getInstance()->pause();
return 0;
}
static int lresume(lua_State * L)
{
RDAudio::getInstance()->resume();
return 0;
}
/******************** for buffer metatable ********************/
static int lBufferGC(lua_State *L)
{
@@ -228,6 +240,8 @@ static const struct luaL_Reg meta_source [] = {
static const struct luaL_Reg audio_funcs [] = {
{"newBuffer", lnewBuffer},
{"newSource", lnewSource},
{"pause", lpause},
{"resume", lresume},
{NULL, NULL}
};

View File

@@ -4,12 +4,12 @@ local AppBase = class("AppBase")
function AppBase:ctor()
local eventDispatcher = cc.Director:getInstance():getEventDispatcher()
local customListenerBg = cc.EventListenerCustom:create("APP_ENTER_BACKGROUND_EVENT", function()
audio.pauseAll()
Rapid2D_CAudio.pause() -- stop OpenAL backend thread
self:onEnterBackground()
end)
eventDispatcher:addEventListenerWithFixedPriority(customListenerBg, 1)
local customListenerFg = cc.EventListenerCustom:create("APP_ENTER_FOREGROUND_EVENT", function()
audio.resumeAll()
Rapid2D_CAudio.resume() -- start OpenAL backend thread
self:onEnterForeground()
end)
eventDispatcher:addEventListenerWithFixedPriority(customListenerFg, 1)