iOS AudioEngine stops looping audio
- cocos2d-x version: 3.17.1
- devices test on: iPad Mini 2, iPhone 6
- developing environments
- Xcode version: Version 10.1 (10B61)
Steps to Reproduce:
Audio suddenly stops, or doesn't resume when entering the running app from the homescreen or after hitting a breakpoint. (happens more often on the ipad mini 2 and in real project where much more is going on)
Tried to create looping background music.
Tested with cpptest NewAudioEngineTest - 8. Test large audio file
Open the cocos2d-x cpptest project NewAudioEngineTest.cpp
Change
LargeAudioFileTest::init()AudioEngine::play2d("audio/LuckyDay.mp3")
to
AudioEngine::play2d("audio/LuckyDay.mp3", true)
Run the app on a ios device and play the music from NewAudioEngine 8. Test large audio file
Either break in the debugger and resume (should be 100%) or try to tab out of the game and back in again.
Music shouldn't be playing anymore. (but you can start it again).
Reproducing it by tabing out of the game and back in, happens more likely when you have mulltiple apps open and running, not sure if this could be memory related.
Additionaly from my observation and debugging so far:
AudioEngineImpl-inl.mm AudioEngineImpl::update(..)
alGetSourcei(alSource, AL_SOURCE_STATE, &sourceState);sets the sourceState to AL_STOPPED
which causes to enter the if conditional
else if (player->_ready && sourceState == AL_STOPPED)
where it gets removed from the audio map. maybe the openal audio streaming gets interrupted?
For more check out my forum post https://discuss.cocos2d-x.org/t/audio-stopping-on-ios/45887/6
Source: cocos2d/cocos2d-x