2016-03-30 15 views
1

サムネイルをクリックすると動画を再生できますが、広告を添付すると広告が再生されます。後で広告を再生するにはどうすればいいですか?tvOSでビデオの再生が終了した後、どのように広告を再生しますか?

func playVideo(){ 

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

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

「AVPlayer」の再生が完了すると、広告を表示します。http://stackoverflow.com/a/12605261/2108547 –

答えて

1

AVPlayerItemDidPlayToEndTimeNotificationに登録しようとしましたか?

、あなたのビデオを再生し、あなたの広告を提示する必要がある場合itemDidFinishPlaying:メソッドを実装するときだけ

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

を追加します。このようなもの:

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) 
} 
関連する問題