LoginSignup
3
2

More than 3 years have passed since last update.

[Cocoa][Swift]AirPlay 2 について

Posted at

HomePod miniは2台でステレオ再生ができるということで購入したのだが、使ってみたところ、それはAirPlay 2を利用した場合だった。MacintoshにレコードプレーヤーをLINE入力で繋いだので、レコードがステレオで再生されることを夢見たのだが、サウンドの入力を出力に繋ぐために利用しているQuickTime PlayerはAirPlay 2に対応していないので、ステレオ再生できない。そもそも、QuickTime Playerを使う必要があるということも面倒なので、レコードプレーヤーの音声を再生するアプリを制作作するため、AirPlay 2 に対応する手順を調べた。

AVAudioSessionのroute-sharing policyに .longForm を設定する

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

AVRouteDetectorを使って出力先があるかどうか調べて、AVRoutePickerView で出力先を選択する。

MPRemoteCommandCenter を使って再生が制御できるようにする。再生中のメディアの情報は MPNowPlayingInfoCente から得る。

AVPlayer 又は AVQueuePlayer を利用するか、 AVSampleBufferAudioRenderer と AVSampleBufferRenderSynchronizer で再生を行う。

情報は少ないが、サンプルコードを見つけた。

【関連情報】
Getting AirPlay 2 into Your App

Integrating AirPlay for Long-Form Video Apps

Cocoa Advent Calendar 2020

Cocoa.swift

Cocoa勉強会 関東

Cocoa練習帳

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2