Short and Sweet: Adding Audio
Apple makes it relatively easy to add audio to your app with AVFoundation, which is a framework that allows you to create and/or add audio or video to your app.
An instance of the AVAudioPlayer class, called an audio player, provides playback of audio data from a file or memory.
I made a simple app to practice and demonstrate how to implement audio into your app, mainly utilizing AVAudioPlayer, and from my experience here three steps that will hopefully help you implement audio into your app.
Step One: Import the AVFoundation Framework
In the Project Navigator, select your project’s name. In the Content Area, select your project’s name under Targets and click “Build Phases.” Expand “Link Binary with Libraries” and click the “+” button to add the “AVFoundation.framework”.
Step Two: Import AVFoundation into your file
Which is as simple as typing out “import AVFoundation” at the top of your file
Step Three: Instantiate and Code
AVAudioPlayer is a class so you must instantiate it.
In order to grab the audio files a URL must be created.
The path for the file is within the bundle (which helps you access the code and resources in a bundle directory), where you’ll insert the name of the audio file. You insert the name of your file (not including its audio type, you will save this for “of Type”) in the parameter for “pathForResource.”
That’s that! Adding audio short and sweet, it’s fun so I suggest you give it a try.