Sound FX not playing after a while

I have loaded all my sound effects and music using the preload methods. The sound of music is played in a loop and always works, however the effects occasionally stop working after the game has been backgrounded and foregrounded a few times. Any suggestions as to why? The code relavant to background/foreground/terminate is posted below.

// 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()->stopAnimation();
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// This function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->startAnimation();
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}

// This function will be called when the app exits
void AppDelegate::applicationWillTerminate()
{
SimpleAudioEngine::sharedEngine()->end();
}

It’s the first time the case ported.
Can you tell me your environment, including
* platform (android/ios/…)
* platform version (e.g. android 2.2)
* device (e.g HTC G7, iTouch3GS…)
* cocos2d-x version
* audio format of this effect

If you can write a simple demo which can reproduce this bug, it will be very helpful to trace it, and will be highly appreciated!

however the effects occasionally stop working after the game has been backgrounded and foregrounded a few times
Does the effect not work at the first time it enter foreground, or does it not work from then on?

Platform: iOS
Platform Version: iOS 4.x
Device: iPhone4, iTouch2, iPad (Mostly iPad)
Cocos2d-x Version: 1.0
Audio Format: Mono Caf

If I get some time I will try to write a hello world that replicates the issue, however it seems to be intermittent as to when it starts happening. Currently it is random as to how many times, or how long the application has been backgrounded before the lack of sound effects start. However when it happens all sound effects stop working. Also, please note that I do call the method to set the volume to 0 when a user disables the sound, but that seems to work correctly.

This happens to me too.
All sound effect not play when I lock/minimize/sleep then immediately make an action that will call any playEffect()
And this still happen while you not lock/minimize/sleep and resume again (but dont rushing to invoke any sound effect).
And the sound effect will play again normally.
This problem only occurs in iPad 3. In iPhone 3GS and iPad 1 it’s working normally.

Platform: iOS
Platform Version: iOS 6
Device: iPad 3
Cocos2d-x Version: 2.03
Audio Format: mp3

It happens to me also. Using iphone 5 with IOS 6 or iPad 2 with IOS 6.

The sound ( mp3 ) seems to not playing after the application going to background

It happens to me also, I using new ipod with IOS6. The sound will not playing after the application going to background, But backgoundmusic is ok, all sound effect can’t play, my sound format is “caf”.

Same here, using WAV files. Background plays no effects.

I also have an issue where the preloaded sound effect will stop working.
I can cause this by loading a level, exiting the level and loading it again.
Background music is ok but not effects.
For me, I don’t have to exit the app itself, just the level.

I wondered if pre-loading the same effect again would be causing it?
I tried to unload the effect but was receiving an error.

Hey Adam,

R u working on the Android or iOS.

I got the same problem in Android, I simply changed some of the function in Java side, try to get rid of the preload() problem in cocos2d-x, so i can play sound effects by using playSoundEffect() directly.

But I the problem on iOS side is a little more tricky, when the game enter background and resume, the background music is always there, while the sound effects could disappear if you quit at the same time u are playing the sound effects, I think that s the reason why people said the problem happened randomly depends on the the times they entering background and resume from it.

The following are the piece of code I used for the pause and resume in AppDelegate.cpp :
// 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()->stopAnimation();

CCDirector::sharedDirector()->pause();

// if you use SimpleAudioEngine, it must be pause
CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
// CocosDenshion::SimpleAudioEngine::sharedEngine()->stopAllEffects();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->stopAnimation();

CCDirector::sharedDirector()->resume();

CCDirector::sharedDirector()->startAnimation();

// if you use SimpleAudioEngine, it must resume here
CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
// CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeAllEffects();
}

I comment out the stopAllEffects() and resumeAllEffects() is because I tried on the them and that doesn’t actually work.

Adam Reed wrote:

I also have an issue where the preloaded sound effect will stop working.
I can cause this by loading a level, exiting the level and loading it again.
Background music is ok but not effects.
For me, I don’t have to exit the app itself, just the level.
>
I wondered if pre-loading the same effect again would be causing it?
I tried to unload the effect but was receiving an error.

Android… I don’t have a apple dev account yet so cant test on an actual iOS device.

adam: you can do it, if you jailbreak it.

anyone solved this issue?
I getting the same problem when sounds stop playing after coming from background

I have also been getting this issue. Sound effects which have been preloaded, will not play after going background->foreground. Sometimes in the first go sometimes after multiple goes.

Platform: iOS
Platform Version: iOS 6.1
Device: iPad 2, iPad 3
Cocos2d-x Version: 2.1.0
Audio Format: mp3

i am having the same issue. And it is too bad as app is now live and also featured by apple in the AppStore. Now we have random users reporting about loosing sound in the app - sound played as SimpleAudioEngine::sharedEngine()->playEffect("xxxxx.caf");

Platform: iOS
Platform Version: iOS 6.1
Device: iPad 2, iPad 3
Cocos2d-x Version: cocos2d-2.1beta3-x-2.1.1
Audio Format: caf

So if anyone got a solution or any information would help to solve this problem, please kindly let us know.

Thanks
-nu1

i am have the same problem. when i play with game which our team developed with cocos2dx, after play some minutes, i found all the sounds have no voice. sound played as SimpleAudioEngine::sharedEngine()->playEffect(“xxxxx.mp3”);

Platform: iOS
Platform Version: iOS 6.1
Device: iPhone4s
Cocos2d-x Version: cocos2d-x-2.0.4
Audio Format: mp3

is anyone have solve this problem? please help me…Tks

I have this same problem too.
Really random for which sfx completely disappears after put the app back from background state.

Platform: iOS
Platform version: iOS 6.1
Device: iPod touch 5 Gen
Cocos2d-x version: cocos2d-x-2.0.3
Audio Format: caf

Wasin Thonkaew wrote:

I have this same problem too.
Really random for which sfx completely disappears after put the app back from background state.
>

I have the same problem too.

The guy in this thread http://www.cocos2d-x.org/boards/6/topics/24461?r=30368 seems to have workaround but I don’t know what exactly he means. Somebody?

another (related?) bug: when i run the soundcloud app on iOS, I don’t ever get anymore sound from my game. even if I restart it.