您是否嘗試註冊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)
}
「AVPlayer」播放完成後呈現廣告,http://stackoverflow.com/a/12605261/2108547 –