根据您的问题和拉米斯的评论/代码,我制作了一个示例代码,您可以尝试
正如JAL所提到的,contentOverlayView
应该是在它前面有/可能是用户与.AVPlayerController
contentOverlayView
AVPlayerController
AVTouchIgnoringView
UIView
contentOverlayView
contentOverlayView
所以另一种解决方案是在 AVPlayerViewController 中添加叠加视图
func addContentOverlayView() {
OverlayView.frame = CGRectMake(0,30,AVPlayerVC.view.bounds.width, 100)
OverlayView.hidden = true
OverlayView.backgroundColor = UIColor ( red: 0.5, green: 0.5, blue: 0.5, alpha: 0.379 )
let btnNext = UIButton(frame:CGRectMake(AVPlayerVC.view.bounds.width - 60,0,60,44))
btnNext.setTitle(">>", forState:.Normal)
btnNext.addTarget(self, action:"playNext", forControlEvents:.TouchUpInside)
// btnNext.layer.borderColor = UIColor ( red: 0.0, green: 0.0, blue: 1.0, alpha: 0.670476140202703 ).CGColor
// btnNext.layer.borderWidth = 1.0
OverlayView.addSubview(btnNext)
let btnReplay = UIButton(frame:CGRectMake((AVPlayerVC.view.bounds.width/2)-40,0,80,44))
btnReplay.setTitle("Replay", forState:.Normal)
btnReplay.addTarget(self, action:"replayVideo", forControlEvents:.TouchUpInside)
OverlayView.addSubview(btnReplay)
let btnPrevious = UIButton(frame:CGRectMake(0,0,80,44))
btnPrevious.setTitle("<<", forState:.Normal)
btnPrevious.addTarget(self, action:"previousVideo", forControlEvents:.TouchUpInside)
OverlayView.addSubview(btnPrevious)
let btnComment = UIButton(frame:CGRectMake((AVPlayerVC.view.bounds.width/2)-70,40,140,44))
btnComment.setTitle("Comments", forState:.Normal)
btnComment.addTarget(self, action:"openComments", forControlEvents:.TouchUpInside)
OverlayView.addSubview(btnComment)
AVPlayerVC.view.addSubview(OverlayView);
}
func playNext() {
prevItem = AVPlayerVC.player?.currentItem
OverlayView.hidden = true
commmentQueuePlayer.advanceToNextItem()
}
func replayVideo() {
OverlayView.hidden = true
AVPlayerVC.player?.currentItem?.seekToTime(kCMTimeZero)
AVPlayerVC.player?.play()
}
func previousVideo() {
OverlayView.hidden = true
if prevItem != AVPlayerVC.player?.currentItem {
if (commmentQueuePlayer.canInsertItem(prevItem!, afterItem:AVPlayerVC.player?.currentItem)) {
//commmentQueuePlayer.insertItem(prevItem!, afterItem:AVPlayerVC.player?.currentItem)
commmentQueuePlayer.replaceCurrentItemWithPlayerItem(prevItem)
prevItem = AVPlayerVC.player?.currentItem
replayVideo()
}
} else {
replayVideo()
//Else display alert no prev video found
}
}
func stopedPlaying() {
if prevItem == nil {
prevItem = AVPlayerVC.player?.currentItem
}
OverlayView.hidden = false
}
在初始设置中,我们设置了 AVPlayerController、AVQueuePlayer 等...那时我们可以在 AVPlayerController 上添加叠加层
对于上一个项目,没有直接可用的项目,并且根据文档,一旦播放下一个项目,该项目将被删除,因此我们有两个选项,例如replaceCurrentItemWithPlayerItem
或insertItem(item: AVPlayerItem, afterItem: AVPlayerItem?)
如果您需要检查完整的代码,可以从以下位置进行检查:
https ://gist.github.com/Pyrolr/debb4fca8f608b1300e099a5b3547031
注意:这就像原型一样,并非在所有情况下都能完美运行,但它可以帮助您理解您想要的基本功能,并且您可以根据您的要求进行改进/优化