我使用AVPlayer和AVPlayerViewController创建了一个视频播放器。我将“allowsExternalPlayback
”属性设置为true,并将“usesExternalPlaybackWhileExternalScreenIsActive
”属性设置为true。但我仍然没有在播放器控件中获得Airplay图标。
player = AVPlayer(URL: url!)
player!.allowsExternalPlayback = true
player?.usesExternalPlaybackWhileExternalScreenIsActive = true
我在ios 9.2上运行我的应用程序。
答案 0 :(得分:2)
您需要添加MPVolumeView才能获得此功能。你可以在这里阅读:https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AirPlayGuide/EnrichYourAppforAirPlay/EnrichYourAppforAirPlay.html
答案 1 :(得分:1)
func appleTv()
{
let rect = CGRect(x: -100, y: 0, width: 0, height: 0)
let airplayVolume = MPVolumeView(frame: rect)
airplayVolume.showsVolumeSlider = false
self.view.addSubview(airplayVolume)
for view: UIView in airplayVolume.subviews {
if let button = view as? UIButton {
button.sendActions(for: .touchUpInside)
break
}
}
airplayVolume.removeFromSuperview()
}