Chapter 2. Media capture with AV Foundation
This chapter covers
- Introducing media capture in AV Foundation
- How video frames flow through the AV Foundation components to a preview layer
- Configuring cameras and toggling device features
- Implementing autofocus and tap-to-focus
- Capturing still images
- Handling UI rotation
To be able to scan barcodes with the iPhone camera, you need to understand two things: AV Foundation’s media capture functionality and its metadata detector.
Most iOS developers have little reason to familiarize themselves with AV Foundation. The usual kinds of apps have no need to capture audio or video. Even less often do developers need to manipulate or compose media. But this knowledge is a requirement for the barcode scanning this chapter is devoted to, so we’ll run through a tutorial on AV Foundation and its components pertinent to media capture.
Chapter 3 will build on this foundation and add the actual barcode scanning via AV Foundation’s metadata detector.
AV Foundation is Apple’s framework for working with audiovisual media. Initially it contained only functions for dealing with audio media, most notably AVAudioPlayer and AVAudioRecorder, which are still available today. The earliest traces of AV Foundation date back to iPhone OS 2.2 and OS X 10.7.