audioSource.isPlaying issues?

Hey,

I’m trying to have a very simple toggle button for some audio… It looks something like this.

// Play pause toggle

if (audio.isPlaying)
{
 audio.Pause();
}
else
{
 audio.Play();
}

This works fine on the Mac, but unfortunately it doesn’t work reliably on the iPhone/iPods. It seems that if you pause a sound (I’m playing back .mp4’s), it seems to return that it is still playing, and thus, won’t resume.

Any ideas?

I would simply add a boolean variable that holds the state.

The topic has come up already and I’m unsure if unity can do anything about it as this fully relies on the iphone hardware decompression etc, not cpu work

I had an awful fear you (or someone just like you) would say that :slight_smile:

I suppose when I hit play, I set off a coroutine that sets that boolean to false after audio.length has ended aswell.

Plus, the user is basically encouraged to move on from that point, etc, so I have to keep it all in sync etc.

Sigh.

Workaround - VCR controls… They’re just always there, even if it’s the height of redundancy :slight_smile:

I’m having the same problem with my iPhone app. I’m using uncompressed audio for a sound effect as recommended in the documentation, but I just can’t get it to stop and start using audio.Play() and audio.Pause() (or audio.Stop()). if I use:

Debug.Log(audio.isPlaying);

to check if the clip is playing it seems that audio.Pause() will stop it, but audio.Play() will not start it again.

I’ve searched the forum but can’t find a solution to this problem. Has anyone been able to work around it?

Thanks.

Play() after Stop() may not work if they are being called within one frame.

Thanks. I don’t think that’s the problem here though, because audio.Play is being called some time after the clip was paused.

I’ve worked around it by using audio.volume = 0.0 in my pause function. This shouldn’t cause problems with processor use because everything else is suspended at this point. Using audio.Stop() seems to work fine when the game ends and I can then restart it as expected. Just not during the game. Odd.