Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2023 Spatial ComputingAudio & Video

WWDC23 · 15 min · Spatial Computing / Audio & Video

Enhance your app’s audio experience with AirPods

Discover how you can create transformative audio experiences in your app using AirPods. Learn how to incorporate AirPods Automatic Switching, use AVAudioApplication to support Mute Control, and take advantage of Spatial Audio to create immersive soundscapes in your app or game.

Watch at developer.apple.com ↗

Transcript all transcripts

Chapters

  • 4:20 — AirPods Automatic Switching for macOS
  • 6:41 — Press to Mute and Unmute
  • 12:02 — Spatial Audio with AirPods

Code shown on screen · 2 snippets

Press to Mute and Unmute API swift · at 8:25 ↗
// Adopting AVAudioApplication into your App
import AVFAudio

// Get the started instance 
let instance = AVAudioApplication.shared

// Register for mute gesture notifications on Notification Center 
AVAudioApplication.inputMuteStateChangeNotification

// Key for mute state
AVAudioApplication.muteStateKey

// Updating AVAudioApplication’s mute state
instance.setInputMuted(...)

// Reading AVAudioApplication’s mute state
instance.isInputMuted
Configure the Input Mute State Change handler (macOS only) swift · at 10:52 ↗
// Configure the Input Mute State Change handler (macOS only)
instance.setInputMuteStateChangeHandler { isMuted in
	//...
	return didSucceed
}

// Optional: let CoreAudio mute your input for you (macOS only)
// Define the Core Audio property
var inputeMutePropertyAddress = AudioObjectPropertyAddress(
	mSelector: kAudioHardwarePropertyProcessInputMute,
	mScope: kAudioObjectPropertyScopeInput,
	mElement:kAudioObjectPropertyElementMain)

// Enable this property when you want to mute your input
UInt32 isMuted = 1; // 1 = muted, 0 = unmuted
AudioObjectSetPropertyData(kAudioObjectSystemObject,
						   &inputeMutePropertyAddress,
						   0,
						   nil,
						   UInt32(MemoryLayout.size(ofValue: isMuted),
						   &isMuted)