Search code examples
iosaudiosdkstatusplayback

iOS API method to ask whether a sound loaded and started by the app is still being played


Is there a method provided by the iOS SDK to allow the application to start a loaded sound, and know when it is finished or still being played?

I'm using this audio library but it lacks that kind of functionality

These are the functions I've been using

To load a sound effect or background music:

OSStatus  SoundEngine_LoadBackgroundMusicTrack(const char* inPath, Boolean inAddToQueue, Boolean inLoadAtOnce)

OSStatus  SoundEngine_LoadEffect(const char* inPath, UInt32* outEffectID)

OSStatus  SoundEngine_LoadLoopingEffect(const char* inLoopFilePath, const char* inAttackFilePath, const char* inDecayFilePath, UInt32* outEffectID)

To play them

OSStatus  SoundEngine_StartBackgroundMusic()

OSStatus  SoundEngine_StartEffect(UInt32 inEffectID)

Solution

  • The answers given to this question are very helpful, since Stormyprods' sound engine is a wrapper for OpenAL

    I used the following code:

    ALint sourceState;
    alGetSourcei(soundID, AL_SOURCE_STATE, &sourceState);
    
    if (sourceState != AL_PLAYING)
    {
        SoundEngine_StartEffect(soundID);
    }
    else
    {
        printf("already playing sfx %d\n", soundID);
    }