Swift AVPlayerViewController添加AirPlay

我试图启用AirPlay与我的AVPlayerViewController 。 在文件中:

https://developer.apple.com/reference/avkit/avplayerviewcontroller

它指出

AVPlayerViewController automatically supports AirPlay, but you need to perform some project and audio session configuration before it can be enabled in your application.

Capabilities选项卡下,我确实启用了audio,AirPlay和图片中的背景模式。 我已经创build了AVPlayerViewController ,如下所示:

 // Create the view controller and player let moviePlayerViewController: AVPlayerViewController = AVPlayerViewController() let moviePlayer = AVPlayer(url: videoUrl!) moviePlayer.allowsExternalPlayback = true moviePlayer.usesExternalPlaybackWhileExternalScreenIsActive = true // Initialize the AVPlayer moviePlayerViewController.player = moviePlayer // Present movie player and play when completion self.present(moviePlayerViewController, animated: false, completion: { moviePlayerViewController.player?.play() }) 

我想到了两条线

 moviePlayer.allowsExternalPlayback = true moviePlayer.usesExternalPlaybackWhileExternalScreenIsActive = true 

将添加AirPlay的支持,但我错了。 我已经读过AirPlay可以通过添加MPVolumeView来使用,但这是一个自定义的video控制器,而不是内置的。 任何帮助将不胜感激。