views:

157

answers:

1

One of my views is a UITableView which acts as the delegate for an AVAudioPlayer and this table essentially plays sounds when you select a certain row with options to repeat the sound after its finished playing.

However, I noticed that if I select a cell with repeat ON for a certain sound and then scroll through the UITableView to select a different sound, it will not call audioPlayerDidFinishPlaying (and therefore not repeat) until after scrolling has stopped. As soon as I stop scrolling, it repeats just fine. Or if I don't scroll at all, it repeats just fine.

What could be happening during scrolling that the UITableView is no longer acting as the delegate and calling audioPlayerDidFinishPlaying? Any thoughts?

+1  A: 

Even though the documentation did not stated it clearly, I suspect that the audioPlayerDidFinishPlaying call is deferred on the main thread (bold sentence by me):

The AVAudioPlayer class lets you play sound in any audio format available in iPhone OS. You use a delegate to handle interruptions (such as an incoming phone call) and to update the user interface when a sound has finished playing. The delegate methods for the AVAudioPlayer class are described in AVAudioPlayerDelegate Protocol Reference.

As long as there are some events to process, like scrolling events, the call is awaiting on the main thread.

Laurent Etiemble
Good catch, thanks Laurent!
iWasRobbed