mirror of https://github.com/axmolengine/axmol.git
fix-157
This commit is contained in:
parent
a3b208075b
commit
a09253c7a2
|
@ -24,7 +24,7 @@ set(COCOS_AUDIO_SRC
|
|||
# stupid, clang always compie .mm as objc/cpp mix obj
|
||||
if(ANDROID)
|
||||
set(COCOS_AUDIO_SRC ${COCOS_AUDIO_SRC}
|
||||
audio/src/AudioEngineImpl.cpp
|
||||
audio/src/alink.cpp
|
||||
)
|
||||
else()
|
||||
set(COCOS_AUDIO_SRC ${COCOS_AUDIO_SRC}
|
||||
|
|
|
@ -35,13 +35,10 @@
|
|||
#define MAX_AUDIOINSTANCES 24
|
||||
#define CC_USE_ALSOFT 0
|
||||
#else
|
||||
#ifdef OPENAL_PLAIN_INCLUDES
|
||||
#include <al.h>
|
||||
#include <alext.h>
|
||||
#else
|
||||
#include <AL/al.h>
|
||||
#include <AL/alext.h>
|
||||
#endif
|
||||
#define AL_ALEXT_PROTOTYPES 1
|
||||
#include "AL/al.h"
|
||||
#include "AL/alc.h"
|
||||
#include "AL/alext.h"
|
||||
#define MAX_AUDIOINSTANCES 32
|
||||
#define CC_USE_ALSOFT 1
|
||||
#endif
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
/* Android clang link workaround for unrefenreced "gnu_objc_personality_v0" */
|
||||
#include "AudioEngineImpl.mm"
|
|
@ -50,6 +50,27 @@ static ALCdevice* s_ALDevice = nullptr;
|
|||
static ALCcontext* s_ALContext = nullptr;
|
||||
static AudioEngineImpl* s_instance = nullptr;
|
||||
|
||||
static void ccALPauseDevice() {
|
||||
ALOGD("%s", "===> ccALPauseDevice");
|
||||
#if CC_USE_ALSOFT
|
||||
alcDevicePauseSOFT(s_ALDevice);
|
||||
#else
|
||||
if(alcGetCurrentContext())
|
||||
alcMakeContextCurrent(nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void ccALResumeDevice() {
|
||||
ALOGD("%s", "===> ccALResumeDevice");
|
||||
#if CC_USE_ALSOFT
|
||||
alcDeviceResumeSOFT(s_ALDevice);
|
||||
#else
|
||||
if(alcGetCurrentContext())
|
||||
alcMakeContextCurrent(nullptr);
|
||||
alcMakeContextCurrent(s_ALContext);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
typedef ALvoid (*alSourceNotificationProc)(ALuint sid, ALuint notificationID, ALvoid* userData);
|
||||
|
@ -88,14 +109,14 @@ void AudioEngineInterruptionListenerCallback(void* user_data, UInt32 interruptio
|
|||
{
|
||||
if (kAudioSessionBeginInterruption == interruption_state)
|
||||
{
|
||||
alcMakeContextCurrent(nullptr);
|
||||
ccALPauseDevice();
|
||||
}
|
||||
else if (kAudioSessionEndInterruption == interruption_state)
|
||||
{
|
||||
OSStatus result = AudioSessionSetActive(true);
|
||||
if (result) NSLog(@"Error setting audio session active! %d\n", static_cast<int>(result));
|
||||
|
||||
alcMakeContextCurrent(s_ALContext);
|
||||
ccALResumeDevice();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -142,16 +163,16 @@ void AudioEngineInterruptionListenerCallback(void* user_data, UInt32 interruptio
|
|||
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive)
|
||||
{
|
||||
ALOGD("AVAudioSessionInterruptionTypeBegan, application != UIApplicationStateActive, alcMakeContextCurrent(nullptr)");
|
||||
alcMakeContextCurrent(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
ALOGD("AVAudioSessionInterruptionTypeBegan, application == UIApplicationStateActive, pauseOnResignActive = true");
|
||||
pauseOnResignActive = true;
|
||||
}
|
||||
|
||||
// We always pause device when interruption began
|
||||
ccALPauseDevice();
|
||||
}
|
||||
|
||||
if (reason == AVAudioSessionInterruptionTypeEnded)
|
||||
else if (reason == AVAudioSessionInterruptionTypeEnded)
|
||||
{
|
||||
isAudioSessionInterrupted = false;
|
||||
|
||||
|
@ -160,9 +181,7 @@ void AudioEngineInterruptionListenerCallback(void* user_data, UInt32 interruptio
|
|||
ALOGD("AVAudioSessionInterruptionTypeEnded, application == UIApplicationStateActive, alcMakeContextCurrent(s_ALContext)");
|
||||
NSError *error = nil;
|
||||
[[AVAudioSession sharedInstance] setActive:YES error:&error];
|
||||
if (alcGetCurrentContext() != nullptr)
|
||||
alcMakeContextCurrent(nullptr);
|
||||
alcMakeContextCurrent(s_ALContext);
|
||||
ccALResumeDevice();
|
||||
if (Director::getInstance()->isPaused())
|
||||
{
|
||||
ALOGD("AVAudioSessionInterruptionTypeEnded, director was paused, try to resume it.");
|
||||
|
@ -183,7 +202,7 @@ void AudioEngineInterruptionListenerCallback(void* user_data, UInt32 interruptio
|
|||
{
|
||||
pauseOnResignActive = false;
|
||||
ALOGD("UIApplicationWillResignActiveNotification, alcMakeContextCurrent(nullptr)");
|
||||
alcMakeContextCurrent(nullptr);
|
||||
ccALPauseDevice();
|
||||
}
|
||||
}
|
||||
else if ([notification.name isEqualToString:UIApplicationDidBecomeActiveNotification])
|
||||
|
@ -201,14 +220,11 @@ void AudioEngineInterruptionListenerCallback(void* user_data, UInt32 interruptio
|
|||
}
|
||||
[[AVAudioSession sharedInstance] setActive:YES error:&error];
|
||||
|
||||
if (alcGetCurrentContext() != nullptr)
|
||||
alcMakeContextCurrent(nullptr);
|
||||
alcMakeContextCurrent(s_ALContext);
|
||||
ccALResumeDevice();
|
||||
}
|
||||
else if (isAudioSessionInterrupted)
|
||||
{
|
||||
ALOGD("Audio session is still interrupted, pause director!");
|
||||
// Director::getInstance()->pause();
|
||||
ALOGD("Audio session is still interrupted!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
/* alink.cpp: only a workaround for solving clang link issue, said: unrefenreced "gnu_objc_personality_v0" */
|
||||
#include "AudioEngineImpl.mm"
|
Loading…
Reference in New Issue