Chapter 15. Video
Simple video playback is performed in a view provided by the Media Player framework. You’ll need to @import MediaPlayer
. There are two relevant classes:
- MPMoviePlayerController
- Vends a view that plays a movie, along with controls letting the user regulate playback.
- MPMoviePlayerViewController
- A UIViewController subclass that owns an MPMoviePlayerController and displays its view.
A simple interface for letting the user trim video (UIVideoEditorController) is also supplied.
Sophisticated video playing and editing can be performed through the AV Foundation framework. I’ll introduce AV Foundation, describing AVPlayer, an alternative class for playing a movie or a sound, and demonstrating AV Foundation’s video- and audio-editing capabilities.
If an MPMoviePlayerController or an AVPlayer produces sound, you may need to concern yourself with your application’s audio session; see Chapter 14. Both classes deal gracefully with the app being sent into the background; they will pause when your app is backgrounded and resume when your app returns to the foreground.
A movie file can be in a standard movie format, such as .mov or .mp4, but it can also be a sound file. An MPMoviePlayerController or MPMoviePlayerViewController is thus an easy way to play a sound file, including a sound file obtained in real time over the Internet, along with standard controls for pausing the sound and moving the playhead — unlike AVAudioPlayer, which, as I pointed out in Chapter 14, lacks a user ...
Get Programming iOS 7, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.