O'Reilly logo

iOS App Development Portable Genius by Richard Wentk

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

caution_exclamation_2c.eps

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required