Playing Sounds and Videos
iOS is capable of complex real-time sound synthesis. But a full introduction to all the features in Core Audio, Media Player, and the other media frameworks would need a much bigger book.
Fortunately, you don’t need to be an expert on synthesis to play a simple sound. You can use a class called AVAudioPlayer to load a sound and play it with just a few lines of code.
Playing a sound with AVAudioPlayer
The AVAudioPlayer class provides simple playback of sampled audio files. The class can do much, and it’s easy to work with. But you must add extra setup code to load a file you package with your app and optionally to handle errors.
AVAudioPlayer is part of the AVFoundation framework. Don’t forget to add this framework to your build and include its headers in your project before you work with it.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access