Adding background and sound effects
After understanding some ways of integrating audio in the app, the most commonly used and easiest way is AVAudioPlayer. Basically, in this recipe, we will be adding background music, which will be running forever, and some sound effects on specific events where the user's attention is required or where the user has to be notified of some change. This adding of background music and sound effects will be done in our game FlyingSpaceship built in the previous chapters.
Getting ready
Before starting with the addition of background music and sound effects on some events, we should have a good understanding of the AVAudioPlayer
class and the AVFoundation
framework. So the prerequisite for this section is to have knowledge of how to play audio using the AVAudioPlayer class as discussed in the preceding recipe.
How to do it…
We have the full game FlyingSpaceship built in which the addition of background music and sound effects will be done as discussed...