63

I am just wondering how you repeat a AVAudioPlayer?

1

3 Answers 3

182

Set the Property numberOfLoops to -1 and it would go into infinite loop.

3
  • 1
    rather do upvote if it really helped you so that it can help other usesr in future... Commented Jul 26, 2011 at 8:30
  • 1
    upvote suggests that this reply helped you and this might be helpful to other users as well.Hope you got my point:) Commented Aug 16, 2011 at 9:31
  • anything for AVPlayer to repeat audio? Commented Jun 16, 2017 at 13:42
15

From the iOS docs:

numberOfLoops

The number of times a sound will return to the beginning, upon reaching the end, to repeat playback.

@property NSInteger numberOfLoops Discussion A value of 0, which is the default, means to play the sound once. Set a positive integer value to specify the number of times to return to the start and play again. For example, specifying a value of 1 results in a total of two plays of the sound. Set any negative integer value to loop the sound indefinitely until you call the stop method.

Availability Available in iOS 2.2 and later. Declared In AVAudioPlayer.h

15

Do you mean 'How do I set an AVAudioPlayer to repeat a sound?' I assume?

if so:

Notice that AVAudioPlayer class has a property called numberOfLoops. If you set this property to a negative integer value, when you play the AVAudioPlayer, it will loop until stopped. You can set the number of loops you'd like to play by making numberOfLoops a positive integer.

Hope that helps!

1
  • Thanks for that, all helps is a big help!
    – Seb OH
    Commented Jul 26, 2011 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.