Creating Audio Apps for watchOS

WWDC 2018

Posted by Den on September 25, 2018 · 13 mins read
Creating Audio Apps for watchOS

Creating Audio Apps for watchOS

WWDC 2018

Creating Audio Apps for watchOS

WWDC 2018

Native Controls

Now playing view

  • Digital Crown controls volume
  • Place in non-scrolling controller
  • Automatically switches source
  • Application tint color

Volume control

  • Controls iPhone or local volume ( Watch )
  • Application tint color

Getting Content

WatchConnectivity

The content might already exist on iPhone.
We can just use watchConnectivity and transfer the file directly over to the Watch

Which one do we use ?

  • URLSession
    - User initiated on Apple Watch
    - Use waitsForConnectivity instead of SCNetworkReachability
    - Requests are proxied through iPhone, when in range
  • WatchConnectivity
    - Initiated on iPhone
    - No need to request from your server again

Set Expectations

  • Instruct your user
  • On the magnetic charger

WatchKit

  • presentMediaPlayerController(with: option: completion: )
  • WKAudioFileQueuePlayer
    - WKAudioFilePlayerItem

AVFoundation

  • AVAudioPlayer
  • AVAudioEngine
  • Playback
    - Background run mode (new)
    - Foreground, screen on
  • Formats supported
    - AAC-LC, AAC-ELD, HE-AAC, HE-AACv2, MP3 (decoding only), Opus

Background Playback ( new )

  • AVFoundation
  • Route picking
  • MediaPayer.framework
  • Restricted to Bluetooth routes just like Music, Podcasts, and Radio

Local Playback

  • Set routeSharingPolicy to longForm on AVAudioSession
  • Call new activate(withOptions: completion: ) method on AVAudioSession
    - On completion, call play()

Route Picker

  • Apple wireless chip, W1
  • Bluetooth headphones
  • If user has an active route, the route picker will select that automatically on your behalf
  • Takes active W1 route from iPhone (Unless iPhone has more priority )
  • If no active routes, route picker will appear

Power

  • Only play audio when necessary
  • AVAudioEngine
    - autoShutdownEnabled on by default

MediaPlayer.framework

  • Provide Now Playing information
  • Now Playing UI will update
  • Handles events

Media remote

  • Use MediaPlayer.framework
  • Handle commands however you wish
  • Sample Link

Audio Experience

  • Auto launch
  • Frontmost App state
  • Notifications
  • Shortcuts

Auto Launch

  • Auto launch Audio Apps
  • Now Playing session on iPhone brings Apple Watch app frontmost
  • Stays frontmost for duration of the session

Now Playing session API

  • You will know when you’re launched for a Now Playing session on iPhone
  • Take your user directly to the view
  • Use handleRemoteNowPlayingActivity() on WKExtensionDelegate

Opt out

  • App can opt out
  • Do the right thing
  • Info.plist key
  • Now Playing app will show if you have opted out

Frontmost App State

  • WatchConnectivity resumes
  • URLSession resumes
  • Frontmost notification
  • Haptics
  • Kept frontmost while playing audio
  • User navigates away
    - Background playback still occurs
  • Properly handle background events
  • The Life of a watchOS App ( WWDC 2017 )

Notifications

Frontmost notifications

  • func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
  • Play haptic

Shortcuts

  • Donate INMediaPlaybackIntent
  • Relevant shortcut API
  • Shortcut phrase