Pre-roll Video Ads before MPMoviePlayerController starts

227 views Asked by At

I am trying to implement Pre-Roll Video Ads to MPMoviePlayerController. I want to add advertisement before my main video starts. So here is my code:

override func viewDidLoad() {
        super.viewDidLoad()

        moviePlayer = MPMoviePlayerController()
        moviePlayer.view.frame = CGRect(x: 0, y: self.view.frame.height/2 - self.view.frame.height/6, width: self.view.frame.width, height: self.view.frame.height/3)

        self.view.addSubview(moviePlayer.view)
        moviePlayer.fullscreen = true
        moviePlayer.controlStyle = MPMovieControlStyle.Embedded
        self.moviePlayer.playPrerollAdWithCompletionHandler { (var error: NSError!) -> Void in
            self.moviePlayer.contentURL = NSURL(string: videoUrl)
            self.moviePlayer.play()
        }
    }

Also I have added MPMoviePlayerController.preparePrerollAds() to my AppDelegate. However I can't add Pre-Roll Video Ads which refers to adUrl in my code. Any help would be appreciated.

0

There are 0 answers