Bug in SimpleAudioEngine::playEffect() on iOS

Hi

I have found a major bug in SimpleAudioEngine::playEffect() on iOS. It stops working after foreground-background transition on some iOS devices. How to reproduce:

  1. Create default cocos project:
    cocos new AudioBugTest -p com.company.audiotest -l cpp -d d:\MyProjects

  2. Add code to AppDelegate::applicationDidFinishLaunching:
    SimpleAudioEngine::getInstance()->preloadBackgroundMusic(“bk.mp3”);
    SimpleAudioEngine::getInstance()->preloadEffect(“click.caf”);
    SimpleAudioEngine::getInstance()->playBackgroundMusic(“bk.mp3”, true);

Replace code in HelloWorld::menuCloseCallback with
SimpleAudioEngine::getInstance()->playEffect(“click.caf”);

Uncomment #define USE_SIMPLE_AUDIO_ENGINE 1 in AppDelegate.cpp

Add bk.mp3 and click.caf to existing Resources folder and include them in XCode project

  1. Run project on device. Click button on the screen, click.caf should be working

  2. Click the Home button on device, application will go to background

  3. Click application icon, application will go to foreground. Click button on the screen. Background music is working, but click.caf IS NOT WORKING anymore!!!

I can reproduce this bug on iPod Touch 6 running iOS 10.3.1
On iPad 3 running iOS 8.4.1 all is working fine (no bug)
Using Cocos 3.15.1, XCode 9
Project files attached
AudioBugTest.zip (64.7 KB)

I have found the same issue here:

1 Like

i’m facing same problem with cocos-3.14.1 version
@konk Did you get any solution for this ?

Can you upgrade your cocos2d-x version?

Hi @slackmoehrle
I have upgraded my cocos2dx version to 3.17 but problem is same . SimpleAudioEngine.mm static_playEffect method called which call SimpleAudioEngine.obj_c class method but SFX not play
Background music working fine with back and forth in iOS

I am stuck on this issue .Please help

@drelaptop. Any ideas?

Using cocos2d-x 3.6, the problem occurs only if I receive a call (and go background). If I press Home and Go back to game the problem doesn’t occur.

Any ideas?

Use

CocosDenshion::SimpleAudioEngine::end();

in
AppDelegate::applicationDidEnterBackground()
or
AppDelegate::applicationWillEnterForeground()

to solve this problem, BUT, in this way you loose the pause/resume background music and has to solve this new problem (for example, you can restart background music again).

This code is already in newer versions. :slight_smile:

I forgot it wasn’t in older versions.