View Full Version : Trying to implement isPlaying on iOS

11-27-2010, 02:43 PM
Apparently one would have to use the AudioServicesAddSystemSoundCompletion which calls back a user function when a player stops playing. Right before the AudioServicesPlaySystemSound.

So I thought I'd add a variable bool isPlaying in class AudioObjectOS which will be changed to false in the user function when the system calls it.

Now, the compiler won't shut up about passing the pointer to the user function in AudioServicesAddSystemSoundCompletion unless that function is declared static which will deny me access to m_audioList. If I put m_audioList static, now the linker starts to complain.

I tested the code without it doing anything and the system calls back my function when something stopped playing, the only problem is how can I use this without making the function static?

11-27-2010, 03:12 PM
Fixed it. Use like this

in AudioHandle AudioManagerOS::Play

AudioObjectOS *pAudio = GetAudioObjectByFileName(fName, bLooping);
if (!pAudio) return soundId;

soundId = pAudio->m_id;
AudioServicesAddSystemSoundCompletion( soundId, NULL, NULL, SetStoppedPlaying, (void*)this);

After telling it to play, you need to set isPlaying to true, but since I'm not using string and list classes, this is how it looks in my code. Hope it makes sence

for (int c = 0 ; c < m_audioListSize ; c++)
if (strcmp(m_audioList[c]->fName, fName) == 0)
m_audioList[c]->isPlaying = true;

in AudioManagerOS.h

static void SetStoppedPlaying(SystemSoundID id, void *mySelf);


void AudioManagerOS::SetStoppedPlaying(SystemSoundID id, void *mySelf)
for (int c = 0 ; c < ((AudioManagerOS*)mySelf)->m_audioListSize ; c++)
if (((AudioManagerOS*)mySelf)->m_audioList[c]->m_id == id)
((AudioManagerOS*)mySelf)->m_audioList[c]->isPlaying = false;

Since -> has priority over casting, use ((AudioManagerOS*)mySelf)-> or you'll get some weird errors.

11-28-2010, 10:27 AM
Nice work! Can I add this to Proton? If there is more to it then what you've posted could you possibly attach a patched created with SVN for me?

11-28-2010, 11:13 AM
Of course you can, the only thing I forgot to add is

bool isPlaying;

in the public part of class AudioObjectOS

I am not sure what you mean here, my english is not my first language, sorry.

If there is more to it then what you've posted could you possibly attach a patched created with SVN for me?