因此,当您点击缩略图时我可以播放视频,但如果我将广告附加到该视频,则广告将播放视频。我如何等待播放广告?
func playVideo(){
player = AVPlayer(URL: NSURL(string: String(vid))!)
player?.play()
if(ALInterstitialAd.isReadyForDisplay()){
ALInterstitialAd.show()
}
}
答案 0 :(得分:1)
您是否尝试注册AVPlayerItemDidPlayToEndTimeNotification
?
添加
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(YourViewController.itemDidFinishPlaying(_:)), name: AVPlayerItemDidPlayToEndTimeNotification, object: nil)
当您播放视频并在需要展示广告时实施itemDidFinishPlaying:
方法。像这样:
func playVideo(){
player = AVPlayer(URL: NSURL(string: String(vid))!)
player?.play()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(YourViewController.itemDidFinishPlaying(_:)), name: AVPlayerItemDidPlayToEndTimeNotification, object: nil)
}
func itemDidFinishPlaying(notification : NSNotification){
if(ALInterstitialAd.isReadyForDisplay()){
ALInterstitialAd.show()
}
NSNotificationCenter.defaultCenter().removeObserver(self, name: AVPlayerItemDidPlayToEndTimeNotification, object: nil)
}