Chapter 16. Video
Video playback is performed using classes provided by the AV Foundation framework (import AVFoundation
), such as AVPlayer. An AVPlayer is not a view; rather, an AVPlayer’s content is made visible through a CALayer subclass, AVPlayerLayer, which can be added to your app’s interface.
An AV Foundation video playback interface can be wrapped in a simple view controller, AVPlayerViewController: you provide an AVPlayer, and the AVPlayerViewController automatically hosts an associated AVPlayerLayer in its own main view, providing standard playback transport controls so that the user can start and stop play, seek to a different frame, and so forth. AVPlayerViewController is provided by the AVKit framework; you’ll need to import AVKit
.
A simple interface for letting the user trim video (UIVideoEditorController) is also supplied. Sophisticated video editing can be performed in code through the AV Foundation framework.
If an AVPlayer produces sound, you may need to concern yourself with your application’s audio session; see Chapter 15. You will almost certainly want the category to be .playback
. AVPlayer deals gracefully with the app being sent into the background: it 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 AVPlayerViewController is an easy way to play a sound file, including a sound file obtained in real time over ...
Get Programming iOS 14 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.