[ios] AirPlay 디바이스 연동

AirPlay는 iOS 기기와 다른 기기 간에 무선으로 멀티미디어 콘텐츠를 전송하는 Apple의 프로토콜이다. AirPlay를 사용하면 iOS 기기에서 음악, 사진, 비디오를 Apple TV, 스피커, 또는 다른 호환 장치로 쉽게 전송할 수 있다.

이제 iOS 앱에서 AirPlay 디바이스를 연동하는 방법을 살펴보겠다.

1. AVRoutePickerView 추가

AirPlay를 지원하는 디바이스를 연결할 수 있는 UI를 만들기 위해 먼저 AVRoutePickerView를 스토리보드나 코드로 추가한다.

import AVKit

let routePickerView = AVRoutePickerView(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
view.addSubview(routePickerView)

2. 선택된 디바이스 처리

사용자가 AirPlay 디바이스를 선택하면 앱에서 이벤트를 처리해야 한다.

routePickerView.delegate = self

func avRoutePickerViewDidPickRoute(_ avRoutePickerView: AVRoutePickerView) {
    // 선택된 디바이스 처리
}

3. 디바이스에서 미디어 재생

디바이스가 선택되면 해당 디바이스로 미디어를 전송해야 한다.

let player = AVPlayer(url: videoURL)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
present(playerViewController, animated: true) {
    player.play()
}

위 과정을 통해 iOS 앱에서 AirPlay 디바이스를 연동할 수 있다. 더 자세한 내용은 Apple’s AVFoundation Documentation을 참고하시기 바랍니다.