我已使用此代码显示了播放按钮
var airplayButton: UIBarButtonItem!
let airView: MPVolumeView = MPVolumeView()
airView.showsRouteButton = true
airView.showsVolumeSlider = false
airView.sizeToFit()
airView.tintColor = UIColor.blackColor()
airplayButton = UIBarButtonItem(customView: airView)
airplayButton.tintColor = UIColor.whiteColor()
现在,我想要显示一个屏幕。 iOS Airplay框架中是否有任何默认方法可以显示它。或者我必须自己设计屏幕。此外,没有代表可以验证设备何时连接,并且电影通过iOS设备在AppleTV上开始流式传输。我只有一个变量来检查,即 externalPlaybackActive
问题是如果我使用变量它不是有效的解决方案,因为我可以在播放期间从Control连接airplay。如果电影在AppleTV上播放,我不想在每秒后运行计时器来检查。有更好的想法吗?
此视频正在“Apple TV”上播放
答案 0 :(得分:3)
这就是我实现它的方式。它就像一个魅力!
Dim TP As New TabPage
TP.Text = " Payment . "
form1.TabControlEx1.TabPages.Add(TP)
form1.TabControlEx1.SelectedTab = TP
Dim child As New FastPayment
child.TopLevel = False
child.FormBorderStyle = Windows.Forms.FormBorderStyle.None
child.Dock = DockStyle.Fill
TP.Controls.Add(child)
child.Show()
//设置AirplayView
//Airplay constants
private var observerContextAirplay = 1
private var propertyToObserveAirplay = "externalPlaybackActive"
// MARK: AirPlay Key-value Observing
func startObservingForAirPlayStatusChanges()
{
self.player.moviePlayer.addObserver(self, forKeyPath: propertyToObserveAirplay, options: .New, context: &observerContextAirplay)
}
func stopObservingForAirPlayStatusChanges()
{
self.player.moviePlayer.removeObserver(self, forKeyPath: propertyToObserveAirplay)
}
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if context == &observerContextAirplay {
if self.player.moviePlayer.externalPlaybackActive == true
{
self.setUpAirPlayView()
}
else if self.player.moviePlayer.externalPlaybackActive == false
{
self.resetPlayerView()
}
}
else {
super.observeValueForKeyPath(keyPath, ofObject: object, change: change, context: context)
}
}
答案 1 :(得分:0)
您好像正在使用AVPlayerViewController
,其contentOverlayView
UIView
属性位于视频播放器和控件之间。
您可以首先在externalPlaybackActive
上放置一个属性观察者,以了解AirPlay播放何时开始。一旦该值为true,请初始化您的UIView,将其添加为您的播放器contentOverlayView
的子视图,然后将其删除。
let subview = UIView() // your view you want to show when AirPlay is active
subview.frame = CGRect(...)
playerVC.contentOverlayView?.addSubview(subview)
playerVC.contentOverlayView?.bringSubviewToFront(subview)