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.
6. watchOS 2.0
• App Extension runs on watch, not on iPhone
• New watchOS APIs for media playback and
recording
• Prepare yourself, they’re limited!
7. 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.
8. 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.
9. 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
11. Video Playback
• WKInterfaceMovie — Canned UI component for
movie playback
• WKInterfaceController — A/V features provided
by primary UI controller class
12. 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.
15. 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
20. 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
27. 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
36. Video Killed The Rolex
Star
Chris Adamson • @invalidname
CocoaConf Columbus • July, 2015
Slides available at slideshare.net/invalidname
Code (eventually) at github.com/invalidname
39. 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
40. 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
41. 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.
49. Place media files that you download from
the network (or transfer from your iOS
app) in a shared group container. Both your
Watch app and WatchKit extension must
have access to the shared group container. In
your extension code, create URLs for any
media files inside the container and use them
to configure the media interfaces.
From watchOS 2.0 Transition Guide
64. 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
65. 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
66. 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:
68. 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
• NSFileManager.containerURLForSecurity
ApplicationGroupIdentifier()
69. Video Killed The Rolex
Star
Chris Adamson • @invalidname
CocoaConf Columbus • July, 2015
Slides available at slideshare.net/invalidname
Code (eventually) at github.com/invalidname