Search code examples
iphoneopenal

iPhone/OpenAL getting sound length (playback time) of a sample


I'm new to OpenAL. I managed to get a soundmanager code that wraps OpenAL for iPhone, so I can load sounds and play them.

But I really need to know how long each sound file is in seconds because I need to call an event as soon as the sound as finished.

I've noticed that there is a way to calculate the length of a sound when populating the buffers(?). Can someone help me with this? Thanks in advance.


Solution

  • float result;
    alGetSourcef(sourceID, AL_SEC_OFFSET, &result);
    return result;
    

    You can use this snippet to get the current playback time of the sound.