Audio stopping on iOS

Hey,

On ios for some reason the audio engine stops all my playing audios, which is an issue for playing music.

AudioEngineImpl::update

alGetSourcei(alSource, AL_SOURCE_STATE, &sourceState);

It seems like OpenAL returns AL_STOPPED which causes to enter the following if conditional

else if (player->_ready && sourceState == AL_STOPPED) {

            std::string filePath;
            if (player->_finishCallbak) {
                auto& audioInfo = AudioEngine::_audioIDInfoMap[audioID];
                filePath = *audioInfo.filePath;
                player->setCache(nullptr); // it's safe for player didn't free audio cache
            }

            AudioEngine::remove(audioID);
            _threadMutex.lock();
            it = _audioPlayers.erase(it);
            _threadMutex.unlock();

            if (player->_finishCallbak) {
                player->_finishCallbak(audioID, filePath); //FIXME: callback will delay 50ms
            }

            delete player;
            _unusedSourcesPool.push_back(alSource);
        }

I haven’t work with OpenAL yet, has anyone any idea what could cause this?
Currently for me it sees to be random.

Thanks
Slei

Hi. We have the same problem. No solution yet.:disappointed_relieved:

If you run cpp-tests on your device do the Audio tests stop in this same way?

I’ve tried it quickly, even with the same files (3 different looping .aac audio files) and it seems to work fine.
so it gonna be interesting what causes the audio issue in my project, since they are using the same functions.

I’ve tested it now several times (in the cpptest app) and it seems to be happening but really rarely.
the AL_STOPPED gets triggered 100% on breakpoints and sometimes when entering the running app from the background (Open app, tab out, open some other apps and then renter the cocos app)

This will cause looped audio played with AudioEngine::play2d("",true) to stop.
I still have no idea when OpenAL sets the state to AL_STOPPED. The main difference to my Project (where it happens all the time) is that there is much more going on, therefore not sure if it could be a Memory issue

I thought maybe thats normal, but I guess it’s not, because AL_STOPPED causes the audio to be removed from the audiomap and therefore can’t be resumed.

From OpenAL alSourcePlay: "The playing source will have its state changed to AL_PLAYING. When called on a source
which is already playing, the source will restart at the beginning. When the attached
buffer(s) are done playing, the source will progress to the AL_STOPPED state. " which would mean openal thinks the buffer has finished playing? Or since bigger audio files get streamed maybe the streaming process gets interrupted and therefore causes it to stop?

ok, would you mind creating a GitHub issue for this, please. https://github.com/cocos2d/cocos2d-x/issues

ok I’ve created an issue for it

1 Like

I’ve updated the git Issue, not sure if Github notifies someone if I mention their name therefore I’ll tag @drelaptop again.

Yes we receive notifications. @drelaptop has moved back home and on to another company now.

1 Like

:o good to know

Good, I’ve never tired to link someone on github yet, therefore I had no idea.

You can tag in GitHub just like you can here with the @ symbol. ID’s may be completely different :slight_smile:

1 Like