gpt4 book ai didi

swift - 视频在 tvOS 中播放完后如何播放广告?

转载 作者:行者123 更新时间:2023-11-28 06:46:08 24 4
gpt4 key购买 nike

因此,当您单击缩略图时我可以播放视频,但如果我将广告附加到它,广告将在视频上播放。之后如何等待播放广告?

func playVideo(){

player = AVPlayer(URL: NSURL(string: String(vid))!)
player?.play()

if(ALInterstitialAd.isReadyForDisplay()){
ALInterstitialAd.show()
}
}

最佳答案

您是否尝试注册 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)
}

关于swift - 视频在 tvOS 中播放完后如何播放广告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36309424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com