Create a simple video playback app with built-in controls.
Using AVKit and AVFoundation, you can quickly create a simple video playback app.
Set Up and Configure the User Interface
Begin by creating the user interface for the player.
Mainfile and drag an AVKit player view object onto the storyboard.
Add pinning constraints to the player view to pin it to its superview’s edges and maintain its aspect ratio, as shown in Figure 1.
Select the player view. In the Attributes inspector, change the Controls Style selection to Floating. This style presents controls matching the ones found in the QuickTime Player app.
Implement Playback Behavior
Now that you’ve created the user interface, it’s time to add the code required to play a video.
Open the assistant editor from the
Mainfile, Control-drag the player view object to the
Viewclass, and add a new
Add the AVKit and AVFoundation frameworks to the
viewmethod, add the following code:
Your app is complete, and you can build and run it on your macOS device.