About [Cocoa] [Swift] AirPlay 2

I bought the HomePod mini because it can play stereo with two units, but when I tried using it, it was when using AirPlay 2. I connected a record player to a Macintosh with LINE input, so I dreamed that the record would play in stereo, but the QuickTime Player used to connect the sound input to the output does not support AirPlay 2. , Stereo playback is not possible. In the first place, it is troublesome to use QuickTime Player, so I investigated the procedure for AirPlay 2 in order to create an application that plays the sound of the record player.

Set .longForm in route-sharing policy of AVAudioSession

let audioSession = AVAudioSession.sharedInstance()
try audioSession.setRouteSharingPolicy(.longForm)
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(AVAudioSessionCategoryPlayback,
                             mode: AVAudioSessionModeDefault,
                             routeSharingPolicy: .longForm )

Use AVRouteDetector to check if there is an output destination, and select the output destination with AVRoutePickerView.

Allow playback to be controlled using MPRemoteCommandCenter. Information on the media being played is obtained from MPNowPlayingInfoCente.

Use AVPlayer or AVQueuePlayer, or play with AVSampleBufferAudioRenderer and AVSampleBufferRenderSynchronizer.

I found a sample code, though there is little information.

【Related information】 Getting AirPlay 2 into Your App
Integrating AirPlay for Long-Form Video Apps
Cocoa Advent Calendar 2020
Cocoa.swift
Cocoa Study Group Kanto
Cocoa Exercise Book

Recommended Posts

About [Cocoa] [Swift] AirPlay 2
[Swift] About generics
[Swift] About enumeration types
[Swift] About protocol extension
[Swift] [Beginner]] About range operators
[Swift] Summary about Bool type
[Swift] About asynchronous processing "Operation"
[macOS] [Cocoa] [Swift] Change IME
[Swift] "for-in statement" about iterative processing
About =
[Swift] A note about function and closure