[updated from previous version to include Watch Connectivity, screenshots of WKInterfaceMovie]
watchOS 2.0 brings media functionality to Apple Watch, offering audio and video playback and audio capture. But lest you plan on writing Logic or Final Cut for the watch: what's available on the wrist has its limits, and you hit them quickly. In this session, we'll see what the WKInterfaceController offers us for miniature mobile media, and how we can get the benefits of AV Foundation and Core Audio by moving our movies, songs, and podcasts back and forth between the watch and the iPhone.
3. watchOS 2.0
• App Extension runs on watch, not on iPhone
• New watchOS APIs for media playback and
recording
• Prepare yourself, they’re limited!
4. From watchOS 2.0 Transition Guide
You must implement your extension using
the frameworks in the watchOS SDK instead
of the iOS SDK. For any features not
available in the provided frameworks, you
must rely on your iPhone app to perform the
corresponding task.
5. From watchOS 2.0 Transition Guide
Your extension now stores files and data on
Apple Watch. Any data that is not part of your
Watch app or WatchKit extension bundle must
be fetched the network or from the companion
iOS app running on the user’s iPhone. You
cannot rely on a shared group container to
exchange files with your iOS app. Fetching files
involves transferring them wirelessly to Apple
Watch.
6. Media files. The Watch app handles audio
and video playback in your app. If your
WatchKit extension downloads media files
from the network or the companion iOS app,
you must place those files in a shared group
container that is accessible to both your Watch
app and WatchKit extension. For more
information about managing media-related
files, see Managing Your Media
From watchOS 2.0 Transition Guide
8. Video Playback
• WKInterfaceMovie — Canned UI component for
movie playback
• WKInterfaceController — A/V features provided
by primary UI controller class
9. WKInterfaceMovie
A WKInterfaceMovie object lets you play
back video and audio content directly from
your interface. A movie object displays a
poster image with a play button on top of it.
When the user taps the play button, WatchKit
plays the movie in a modal interface.
12. Video Gravity
• Conceptually identical to video gravity constants in AV
Foundation
• Resize — stretch pixels to fill container
• Aspect (Fit) — honoring aspect ratio, scale to reach
one set of bounds (top/bottom or right/left), then
letter-/pillar-box
• Aspect Fill — honoring aspect ratio, scale to reach
both sets of bounds, allowing contents to be
clipped if needed
17. WKInterfaceController
• Media playback and recording methods
provided by the base controller class
• Can use these to play video whenever the app
decides it’s time to do so
24. WKInterfaceController Audio
• Playback works just like video
• Same recommendation for audio bitrate: 32
kbps
• Audio playback always uses Bluetooth
headphones/speakers if paired, otherwise
internal speaker
33. Video Killed The Rolex
Star
Chris Adamson • @invalidname
CocoaConf San Jose • November, 2015
Slides available at slideshare.net/invalidname
Code (eventually) at github.com/invalidname
36. AVFoundation, Core Image, and Core Audio are
huge and complex, but required for lots of app
types. Will any audio, video, or image APIs be
available? Will they only be possible through
limited, high-level interfaces?
http://www.marco.org/2015/05/28/watch-sdk-questions
37. Available System Technologies
Extensions built specifically for watchOS 2 have access to the
following system frameworks:
ClockKit
Contacts
Core Data
Core Foundation
Core Graphics
Core Location
Core Motion
EventKit
Foundation
HealthKit
HomeKit
ImageIO
MapKit
Mobile Core Services
PassKit
Security
Watch Connectivity
WatchKit
Notice the absence of AV Foundation, Core Audio, Core
Media, and Core Video
38. From watchOS 2.0 Transition Guide
You must implement your extension using
the frameworks in the watchOS SDK instead
of the iOS SDK. For any features not
available in the provided frameworks, you
must rely on your iPhone app to perform the
corresponding task.
46. Watch Connectivity
The Watch Connectivity framework
(WatchConnectivity.framework)
provides a two-way communications conduit
between an iOS app and a WatchKit
extension on a paired Apple Watch. Apps
use this framework to pass files and data
back and forth. Most transfers happen in the
background when the receiving app is
inactive. When the app wakes up, it is
notified of any data that arrived while it was
inactive. Live communication is also possible
when both apps are active.
51. Watch: receive file
func session(session: WCSession, didReceiveFile file: WCSessionFile) {
NSLog ("didReceiveFile: (file)")
let docsURL = NSFileManager.defaultManager().URLsForDirectory(
NSSearchPathDirectory.DocumentDirectory,
inDomains: NSSearchPathDomainMask.UserDomainMask).first
let storageURL = docsURL?.URLByAppendingPathComponent(
file.fileURL.lastPathComponent!)
do {
try NSFileManager.defaultManager().copyItemAtURL(file.fileURL,
toURL: storageURL!)
pushControllerWithName("player", context: storageURL)
} catch let error as NSError {
NSLog ("copy error: (error)")
}
}
file: If you want to keep the file referenced by this parameter, you must move it synchronously to a new
location during your implementation of this method. If you do not move the file, the system deletes it after
this method returns.
57. Export Preset Names for Apple Devices
You use these export options to produce files that can be played on the specific
Apple devices.
Declaration
SWIFT
let AVAssetExportPresetAppleM4VCellular: String
let AVAssetExportPresetAppleM4ViPod: String
let AVAssetExportPresetAppleM4V480pSD: String
let AVAssetExportPresetAppleM4VAppleTV: String
let AVAssetExportPresetAppleM4VWiFi: String
let AVAssetExportPresetAppleM4V720pHD: String
let AVAssetExportPresetAppleM4V1080pHD: String
let AVAssetExportPresetAppleProRes422LPCM: String
58. AVAssetWriter
• Low-level access for writing media files
• Allows you to specify output size, encoding
settings, bitrate, etc.
• Requires you to write each CMSampleBuffer
individually
59. AVAssetWriterInput
SWIFT
let AVVideoCodecKey: String
let AVVideoCodecH264: String
let AVVideoCodecJPEG: String
let AVVideoCodecAppleProRes4444: String
let AVVideoCodecAppleProRes422: String
let AVVideoWidthKey: String
let AVVideoHeightKey: String
let AVVideoCompressionPropertiesKey: String
let AVVideoAverageBitRateKey: String
let AVVideoQualityKey: String
let AVVideoMaxKeyFrameIntervalKey: String
let AVVideoProfileLevelKey: String
let AVVideoProfileLevelH264Baseline30: String
let AVVideoProfileLevelH264Baseline31: String
let AVVideoProfileLevelH264Baseline41: String
let AVVideoProfileLevelH264Main30: String
let AVVideoProfileLevelH264Main31: String
let AVVideoProfileLevelH264Main32: String
let AVVideoProfileLevelH264Main41: String
let AVVideoProfileLevelH264High40: String
let AVVideoProfileLevelH264High41: String
let AVVideoPixelAspectRatioKey: String
let AVVideoPixelAspectRatioHorizontalSpacingKey:
String
let AVVideoPixelAspectRatioVerticalSpacingKey:
String
let AVVideoCleanApertureKey: String
let AVVideoCleanApertureWidthKey: String
let AVVideoCleanApertureHeightKey: String
let AVVideoCleanApertureHorizontalOffsetKey:
String
let AVVideoCleanApertureVerticalOffsetKey:
String
Video Settings
These constants define dictionary keys for configuring video
compression and compression settings for video assets.
- initWithMediaType:outputSettings:sourceFormatHint:
61. Takeaways
• Basic support for file-based audio/video
playback and audio recording
• Playback files are either in your bundle or
downloaded by your iOS app + extension
• Any downloading or media processing needs to
be performed on your iPhone, then sent to watch
extension/app via Watch Connectivity
62. Video Killed The Rolex
Star
Chris Adamson • @invalidname
CocoaConf San Jose • November, 2015
Slides will be at slideshare.net/invalidname
Code (eventually, maybe) at github.com/invalidname