1

So I can video to play when you click on the thumbnail but if I attach the ad to it, the ad will play over the video. how do I wait to play the ad after?

func playVideo(){

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

    if(ALInterstitialAd.isReadyForDisplay()){
        ALInterstitialAd.show()
    }
}
Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
Aknapp
  • 35
  • 7

1 Answers1

1

Did you try to register for AVPlayerItemDidPlayToEndTimeNotification?

Just add

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(YourViewController.itemDidFinishPlaying(_:)), name: AVPlayerItemDidPlayToEndTimeNotification, object: nil)

when you play your video and implement the itemDidFinishPlaying: method when you need to present your advertising. Something like this:

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)
}
Nicola Giancecchi
  • 3,045
  • 2
  • 25
  • 41