Playback Application For Mac
The best way for you to learn AVKit and AVFoundation is to dive in and build your first playback app. This chapter shows you how to get started with these frameworks by walking you through the development of a basic app for iOS, tvOS, and macOS to play media served using HTTP Live Streaming. This project requires that you be familiar with developing apps for at least one of these platforms. For more information, see Start Developing iOS Apps (Swift) and Mac App Programming Guide. The example projects in this chapter are written in Swift 3 and require Xcode 8.0 or later.
iOS and tvOS
Download Colibri DAC DSD Test for macOS 10.10 or later and enjoy it on your Mac. A simple app that enables you to try different DSD playback modes such as DoP, DoPA and PCM. Simply load a DSD/FLAC/WAVE file, select your audio device and hit one of the playback options. Besides Video File Playback, version 2.0 includes the following new features: – Fully redesigned user interface. The new modern user interface provides a better look and feel, and easier and faster access to all the settings. – Mirror any application window instead of the full screen.
Create a new Xcode project for an iOS or tvOS app using the Single View Application template.
Product Name:
AVBasicPlayback
Language: Swift
Devices: Universal (iOS only)
Configuring the Project’s App Transport Security
Begin by configuring the project’s App Transport Security so your app can successfully connect to the remote server.
In the project navigator, locate the app’s
Info.plist
file. Right-click this file and select Open As > Source Code.Add the following entry before the closing
</dict>
tag:Adding this entry ensures that the app can successfully retrieve the media served from
devimages.apple.com.edgekey.net
.
Setting up the Audio Session
Open the
AppDelegate.swift
class. Above the class definition, import the AVFoundation framework.In the
application:didFinishLaunchingWithOptions:
method, set the app’s audio session category toAVAudioSessionCategoryPlayback
.Setting the audio session category ensures that the application has the audio behavior expected of a media playback app.
Configuring the User Interface
Select the
Main.storyboard
file. In the Object library’s search field, typebutton
to find theButton
object.Drag the
Button
object into the View Controller Scene’s view and give it the titlePlay Video
.Add alignment constraints so the button is centered both horizontally and vertically.
Implementing the Playback Behavior
In the project navigator, select the
Main.storyboard
file and open the assistant editor.Control-drag from the
Play Video
button to theViewController.swift
class to add a new@IBAction
method calledplayVideo
.Close the assistant editor and select the
ViewController.swift
class in the project navigator. Above the class definition, import the AVKit and AVFoundation frameworks.In the
playVideo
method, add the following implementation:
Your app is complete, and you can run it in the Simulator or on your iOS or tvOS device. In only a few lines of code, you’ve created a full-featured playback app.
macOS
Create a new Xcode project for a Cocoa app using the Cocoa Application template.
Product Name:
AVBasicPlayback
Language: Swift
Use Storyboards: true
Create Document-Based Application: false
Configuring the Project’s App Transport Security
Begin by configuring the project’s App Transport Security so your app can successfully connect to the remote server.
In the project navigator, locate the app’s
Info.plist
file. Right-click this file and select Open As > Source Code.Add the following entry before the closing
</dict>
tag:Adding this entry ensures that the app can successfully retrieve the media served from
devimages.apple.com.edgekey.net
.
Configuring the User Interface
In the project navigator, select the
Main.storyboard
file. In the Object library’s search field, typeplayer
to find theAVKit Player View
object.Drag the
AVKit Player View
object into the View Controller Scene’s view.Add pinning constraints to the player view to pin it to its superview’s edges and maintain its aspect ratio.
Select the player view. In the Attributes inspector, change the Controls Style selection to Floating.
This style presents controls matching the ones found in Quicktime Player.
Implementing the Playback Behavior
While in the
Main.storyboard
file, open the assistant editor.Control-drag from the player view object to the
ViewController.swift
class and add a new@IBOutlet
calledplayerView
.Close the assistant editor and select the
ViewController.swift
class in the project navigator. Above the class definition, import the AVKit and AVFoundation frameworks.In the
viewDidLoad
method, add the following implementation:
Your app is complete, and you can run it. In only a few lines of code, you’ve created a full-featured playback app.
Playback Application For Mac High Sierra
Playback Application For Mac Catalina
Copyright © 2018 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2018-01-16