In the previous part of this tutorial, we finished up restructuring and unit testing the on-screen animation code for our sample application. We did still have some issues outstanding with the sound, however, which we will clean up in this part. As always, the source code for this tutorial may be found on GitHub. This part’s code is in the Version7 directory.

Specifically, we have one problem and one outstanding requirement. The problem is that the first time the animation runs, the bounce sound is late in playing. We’re using the AudioServicesPlaySystemSound function to play our sound. This works fine, but it can be slow to react. The problem is that the sound file isn’t really loaded, parsed and queued up until we actually go to play the sound. As a result, there’s a delay between when we ask it to play and it actually plays. We can get around this by using an AVAudioPlayer instead.