openfrog
openfrog

Reputation: 40735

How to get notified when AVAudioPlayer loops back to the beginning?

I'm playing a sound file in a loop and need to restart an animation with it every time the loop starts from the beginning.

I couldn't find a delegate method for it in the documentation. Is there a way to get notified when the player loops around to the beginning?

My approach was to use a timer which checks current play time every few milliseconds but this sounds like a horrible solution.

Upvotes: 2

Views: 500

Answers (2)

Andy Dent
Andy Dent

Reputation: 17969

No, AFAIK your solution is the only one which works. The finishedPlaying method is not called whilst looping so sampling the position is the only technique.

I'm updating some inherited code to add looping and came to this conclusion under iOS8.

Upvotes: 1

Satyajit
Satyajit

Reputation: 3859

You can set up a delegate for the avaudioplayer instance. Then the delegate will be notified whenever the sound has successfully finished playing. Then you can probably restart the player to play again and restart your animation. Just off the top of my head. Look here for more information.

Upvotes: 0

Related Questions