Sound FX not playing after a while

Hey guys, does the team set to solve this issue in the future?
I experienced more problem with CocosDenshion nowsday. For .caf file, and only for some files, I can’t adjust its effect volume thus it will be played with its normal volume setting all the time.

Maybe it’s time to build a new audio manager, one that only uses the more modern native players in each platform (some have mentioned OpenAL). I know that I have run in to issues with playEffect on Android if the audio is over 5-6 seconds (the sound just cuts off) and it would be nice to get a sound effect to play as a CCFiniteTimeAction so it plays well in a CCSequence.

Justin Hawkwood wrote:

Maybe it’s time to build a new audio manager, one that only uses the more modern native players in each platform (some have mentioned OpenAL). I know that I have run in to issues with playEffect on Android if the audio is over 5-6 seconds (the sound just cuts off) and it would be nice to get a sound effect to play as a CCFiniteTimeAction so it plays well in a CCSequence.
Unified OpenAL engine is already in develop branch, but it is not for android. On android OpenAL have big latency, and SoundPool/OpenSL AFAIK are only available options. Someone tried to use AudioFlinger directly (it’s android system audio server) via dlopen(), but some device vendors added changes to AudioFlinger so dlopen() cannot load it correctly; on devices where it worked OK latency was the same with SoundPool/OpenSL.

There was issues with SoundPool on Samsung S2, but I personally never heard about issues on other devices.

Same Problem for me too…
All sound fx working; Phone lock —> unlock —> no sound fx work, except for BGM.

Happens only with certain devices:
iPhone 4S running iOS7; iPhone 5 running iOS6; iPad 3 (iOS 6)

where as all android devices (that I tested) play it right and following iOS device(s) play it right:
iPod Touch (iOS 5),

I found an intermittent case of this using various iOS devices running iOS 6 & 7 using the TestCpp.app from Cocos2d-x 2.2. The problem is that sound effects may not play after waking from an auto-lock time out when background music is also playing. The issue is not 100% but very frequent.

Steps to recreate:

  1. In Settings.app, set your auto-lock to 1 minute.
  2. Launch TestCpp.app on the device, not through Xcode as the device will not auto-lock when running in debugger.
  3. Go to CocosDenshionTest
  4. Tap “play background music”
  5. Tap “play effect” to verify it plays
  6. Wait for device to auto-lock
  7. After it fully locks, unlock device and tap the “play effect” button. Sound effect often will not play.
    note: exiting the app via the device’s home button and coming back rarely fixed the issue.
  8. Stop the background music
  9. Wait for device to auto-lock
  10. After it fully locks, unlock device (did the background music start for you too?) and tap “play effect”; it should play.

I think the issue may have something to do with AVAudioPlayer not properly pausing and thus putting the sound engine in a weird state, but I tried swapping the order of pausing/resuming when backgrounding and that didn’t help.

I found a possible solution to my issue, it’s a three parter:

  1. CocosDenshion should only pause effects/bgm that is currently playing (see step 9 from previous post) https://github.com/cocos2d/cocos2d-x/pull/3946
  2. in AppDelegate.cpp don’t pause/resume the background music, let the OS just fade it out. (I realize this is iOS specific so some modifications may need to accomodate other OSs)
  3. (optional?) in AppController.mm add pauseAllEffects and resumeAllEffects to applicationWillResignActive and applicationDidBecomeActive, respectively.
1 Like

Justin Hawkwood wrote:

I found a possible solution to my issue, it’s a three parter:

  1. CocosDenshion should only pause effects/bgm that is currently playing (see step 9 from previous post) https://github.com/cocos2d/cocos2d-x/pull/3946
  2. in AppDelegate.cpp don’t pause/resume the background music, let the OS just fade it out. (I realize this is iOS specific so some modifications may need to accomodate other OSs)
  3. (optional?) in AppController.mm add pauseAllEffects and resumeAllEffects to applicationWillResignActive and applicationDidBecomeActive, respectively.

This fixed the problem for me! Thank you!

Justin Hawkwood wrote:

I found a possible solution to my issue, it’s a three parter:

  1. CocosDenshion should only pause effects/bgm that is currently playing (see step 9 from previous post) https://github.com/cocos2d/cocos2d-x/pull/3946
  2. in AppDelegate.cpp don’t pause/resume the background music, let the OS just fade it out. (I realize this is iOS specific so some modifications may need to accomodate other OSs)
  3. (optional?) in AppController.mm add pauseAllEffects and resumeAllEffects to applicationWillResignActive and applicationDidBecomeActive, respectively.

Nice answer! Thank Justin. It resolved my issue!

CocosDenshion is very powerful but still has some issues, especially when integrating Cocos2d-x. For example, background music which was stopped will automatically replay when you lock then unlock iOS device. Also, there aren’t any function which allows to play 2 or more effects simultaneously with different volume.

Same issue here on iOS and Cocos2d-x 3.4

Only solution that worked

-Removed pause/resume the background music
-Added pauseAllEffects and resumeAllEffects in AppDelegate.cpp applicationWillEnterForeground/applicationDidEnterBackground

2 Likes

I’ve had effects which do not play all the time. In my case it was on Android 5. Unfortunately, I had to switch to fmod for my audio requirements.

I’ve been experience intermittent problems with cocos2d-x 3.4 on iOS 8 devices, sometimes there’s no background music, sometimes there’s no sound effect, but it only happens on some devices and happen randomly.

I used festival’s solution by removing the pauseBackgroundMusic / resumeBackgroundMusic calls, and replace them with pauseAllEffects / resumeAlleffects in AppDelegate.cpp , after reinstalling the app , the problem seems gone.

So give it a try if you have similar problems and for cocos2d-x developers - please help look into the issue.

1 Like

pause:

  auto audio = SimpleAudioEngine::getInstance();
  audio->pauseBackgroundMusic();

resume:

  auto audio = SimpleAudioEngine::getInstance();
  audio->resumeBackgroundMusic();
  if (!audio->isBackgroundMusicPlaying()) {
    audio->playBackgroundMusic("game.mp3", true);
  }

this work fine)