mirror of https://github.com/axmolengine/axmol.git
fixed #1338:stop animation when entering background and start animation when comming to foreground
This commit is contained in:
parent
f8ebbccb98
commit
5cc1f7d230
|
@ -113,6 +113,10 @@ NSString * const kCDN_AudioManagerInitialised = @"kCDN_AudioManagerInitialised";
|
|||
}
|
||||
|
||||
-(void) resume {
|
||||
if (!self->systemPaused) {
|
||||
return;
|
||||
}
|
||||
|
||||
[audioSourcePlayer play];
|
||||
}
|
||||
|
||||
|
@ -542,17 +546,18 @@ static BOOL configured = FALSE;
|
|||
{
|
||||
[self.backgroundMusic load:filePath];
|
||||
|
||||
if (!willPlayBackgroundMusic || _mute) {
|
||||
CDLOGINFO(@"Denshion::CDAudioManager - play bgm aborted because audio is not exclusive or sound is muted");
|
||||
return;
|
||||
}
|
||||
|
||||
if (loop) {
|
||||
[self.backgroundMusic setNumberOfLoops:-1];
|
||||
} else {
|
||||
[self.backgroundMusic setNumberOfLoops:0];
|
||||
}
|
||||
[self.backgroundMusic play];
|
||||
if (loop) {
|
||||
[self.backgroundMusic setNumberOfLoops:-1];
|
||||
} else {
|
||||
[self.backgroundMusic setNumberOfLoops:0];
|
||||
}
|
||||
|
||||
if (!willPlayBackgroundMusic || _mute) {
|
||||
CDLOGINFO(@"Denshion::CDAudioManager - play bgm aborted because audio is not exclusive or sound is muted");
|
||||
return;
|
||||
}
|
||||
|
||||
[self.backgroundMusic play];
|
||||
}
|
||||
|
||||
-(void) stopBackgroundMusic
|
||||
|
@ -713,7 +718,7 @@ static BOOL configured = FALSE;
|
|||
[self audioSessionResumed];
|
||||
}
|
||||
|
||||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
|
||||
#if __CC_PLATFORM_IOS >= 40000
|
||||
-(void) endInterruptionWithFlags:(NSUInteger)flags {
|
||||
CDLOGINFO(@"Denshion::CDAudioManager - interruption ended with flags %i",flags);
|
||||
if (flags == AVAudioSessionInterruptionFlags_ShouldResume) {
|
||||
|
|
|
@ -88,6 +88,7 @@ void* CDloadWaveAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outD
|
|||
theData = malloc(dataSize);
|
||||
if (theData)
|
||||
{
|
||||
memset(theData, 0, dataSize);
|
||||
AudioFileReadBytes(afid, false, 0, &dataSize, theData);
|
||||
if(err == noErr)
|
||||
{
|
||||
|
@ -195,6 +196,7 @@ void* CDloadCafAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDa
|
|||
theData = malloc(dataSize);
|
||||
if (theData)
|
||||
{
|
||||
memset(theData, 0, dataSize);
|
||||
AudioBufferList theDataBuffer;
|
||||
theDataBuffer.mNumberBuffers = 1;
|
||||
theDataBuffer.mBuffers[0].mDataByteSize = dataSize;
|
||||
|
|
|
@ -521,7 +521,7 @@ static BOOL _mixerRateSet = NO;
|
|||
if (soundId >= bufferTotal) {
|
||||
//Need to resize the buffers
|
||||
int requiredIncrement = CD_BUFFERS_INCREMENT;
|
||||
while (bufferTotal + requiredIncrement <= soundId) {
|
||||
while (bufferTotal + requiredIncrement < soundId) {
|
||||
requiredIncrement += CD_BUFFERS_INCREMENT;
|
||||
}
|
||||
CDLOGINFO(@"Denshion::CDSoundEngine - attempting to resize buffers by %i for sound %i",requiredIncrement,soundId);
|
||||
|
@ -1379,12 +1379,11 @@ static BOOL _mixerRateSet = NO;
|
|||
@synthesize filePath, soundId;
|
||||
|
||||
-(id) init:(int) theSoundId filePath:(const NSString *) theFilePath {
|
||||
if ((self = [super init])) {
|
||||
soundId = theSoundId;
|
||||
filePath = [theFilePath copy];//TODO: is retain necessary or does copy set retain count
|
||||
[filePath retain];
|
||||
}
|
||||
return self;
|
||||
if ((self = [super init])) {
|
||||
soundId = theSoundId;
|
||||
filePath = [theFilePath copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void) dealloc {
|
||||
|
|
|
@ -169,7 +169,7 @@ void SimpleAudioEngine::end()
|
|||
s_pEngine = NULL;
|
||||
}
|
||||
|
||||
static_end();
|
||||
static_end();
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
|
||||
|
@ -184,42 +184,42 @@ void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
|
|||
|
||||
void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData)
|
||||
{
|
||||
static_stopBackgroundMusic();
|
||||
static_stopBackgroundMusic();
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::pauseBackgroundMusic()
|
||||
{
|
||||
static_pauseBackgroundMusic();
|
||||
static_pauseBackgroundMusic();
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::resumeBackgroundMusic()
|
||||
{
|
||||
static_resumeBackgroundMusic();
|
||||
static_resumeBackgroundMusic();
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::rewindBackgroundMusic()
|
||||
{
|
||||
static_rewindBackgroundMusic();
|
||||
static_rewindBackgroundMusic();
|
||||
}
|
||||
|
||||
bool SimpleAudioEngine::willPlayBackgroundMusic()
|
||||
{
|
||||
return static_willPlayBackgroundMusic();
|
||||
return static_willPlayBackgroundMusic();
|
||||
}
|
||||
|
||||
bool SimpleAudioEngine::isBackgroundMusicPlaying()
|
||||
{
|
||||
return static_isBackgroundMusicPlaying();
|
||||
return static_isBackgroundMusicPlaying();
|
||||
}
|
||||
|
||||
float SimpleAudioEngine::getBackgroundMusicVolume()
|
||||
{
|
||||
return static_getBackgroundMusicVolume();
|
||||
return static_getBackgroundMusicVolume();
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::setBackgroundMusicVolume(float volume)
|
||||
{
|
||||
static_setBackgroundMusicVolume(volume);
|
||||
static_setBackgroundMusicVolume(volume);
|
||||
}
|
||||
|
||||
float SimpleAudioEngine::getEffectsVolume()
|
||||
|
|
|
@ -57,13 +57,13 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
CCDirector::sharedDirector()->pause();
|
||||
CCDirector::sharedDirector()->stopAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
CCDirector::sharedDirector()->resume();
|
||||
CCDirector::sharedDirector()->startAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
|
|||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground() {
|
||||
CCDirector::sharedDirector()->pause();
|
||||
CCDirector::sharedDirector()->stopAnimation();
|
||||
|
||||
// if you use SimpleAudioEngine, it must be pause
|
||||
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
|
@ -45,7 +45,7 @@ void AppDelegate::applicationDidEnterBackground() {
|
|||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground() {
|
||||
CCDirector::sharedDirector()->resume();
|
||||
CCDirector::sharedDirector()->startAnimation();
|
||||
|
||||
// if you use SimpleAudioEngine, it must resume here
|
||||
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
|
|
|
@ -66,7 +66,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
CCDirector::sharedDirector()->pause();
|
||||
CCDirector::sharedDirector()->stopAnimation();
|
||||
|
||||
// if you use SimpleAudioEngine, it must be pause
|
||||
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
|
@ -75,7 +75,7 @@ void AppDelegate::applicationDidEnterBackground()
|
|||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
CCDirector::sharedDirector()->resume();
|
||||
CCDirector::sharedDirector()->startAnimation();
|
||||
|
||||
// if you use SimpleAudioEngine, it must resume here
|
||||
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
|
|
|
@ -44,7 +44,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
CCDirector::sharedDirector()->pause();
|
||||
CCDirector::sharedDirector()->stopAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->pauseAllEffects();
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ void AppDelegate::applicationDidEnterBackground()
|
|||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
CCDirector::sharedDirector()->resume();
|
||||
CCDirector::sharedDirector()->startAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->resumeAllEffects();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue