※ 動画広告は現在限定されたパートナー様のみご利用頂けます
RFPPlayerControl
動画広告の場合、RFPInstreamInfoModel.isVideo()
がtrue
を返します。これを利用して動画広告か否かを判定することができます。
動画広告で利用するRFPInstreamAdLoaderDelegateのmethodは2つあります。
viewControllerForPresentingModalView
readyToPlay(with playerControl: RFPPlayerControl!)
playerControl.play()
を実行しても再生されませんのでご注意ください。RFPInstreamAdLoader.getVideoControl(withFrame:infoModel:)
を利用してRFPPlayerControl
を取得できます。
Video再生の場合はRFPInstreamAdLoaderDelegate.viewControllerForPresentingModalView
を必ず指定してください。
こちらは動画のFullscreen切替の際に必要となります。
戻り値は呼び出し元のUIViewControllerを指定してください。
func rfpInstreamAdLoaderDidFinishLoadingAd(withReturn instreamAdLoader: RFPInstreamAdLoader!, instreamInfoModels: [Any]!) {
// インフィード広告情報を受け取る
for model: RFPInstreamInfoModel in instreamInfoModels as! [RFPInstreamInfoModel] {
if (model.isVideo()) {
// RFPPlayerControlを取得
let playerControl = instreamAdLoader.getVideoControl(withFrame: containerView.bounds, infoModel: model)!
// playerUiView以外は設定しない
containerView.subviews.forEach { subview in
subview.removeFromSuperview()
}
containerView.addSubview(playerControl)
}
}
}
// ※ 動画広告再生の場合は必須
func viewControllerForPresentingModalView() -> UIViewController! {
return self
}
再生準備が完了すると、RFPInstreamAdLoaderDelegate.readyToPlay(with:)
が呼び出されます。
プレイヤーの初期状態では、一時停止状態です。
func readyToPlay(with playerControl: RFPPlayerControl!) {
// 再生
playerControl.play()
// 一時停止
playerControl.pause()
}
RFPPlayerControl.play()
を利用して再生を開始してください。
RFPPlayerControl.pause()
で一時停止することも可能です。
// 再生
playerControl.play()
// 一時停止
playerControl.pause()
(v2.7.0以上で利用可能)
再生が終了すると、RFPInstreamAdLoaderDelegate.didPlayToEndTime(with:)
が呼び出されます。
func didPlayToEndTime(with playerControl: RFPPlayerControl!) {
// 再生終了時の処理
}
(v2.5.0以上、iOS11以上で利用可能)
RFPでは端末の内部ストレージに動画広告をある程度キャッシュ(HLSダウンロード保存)し、通信量削減および動画広告再生レスポンスの改善を行います。
キャッシュ容量はRFPが推奨する設定値を使用します。この値はアプリ側から変更することが可能です。
キャッシュ容量を変更したい場合、RFP.rfpSetVideoCacheSize(_:)
を利用してキャッシュ容量を設定してください。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// 現在の設定を取得
let size = RFP.rfpGetVideoCacheSize()
// videoキャッシュを100MBに設定
RFP.rfpSetVideoCacheSize(100);
// videoキャッシュを無効にする
RFP.rfpSetVideoCacheSize(0);
// ※ rfpSetVideoCacheSizeは必ずrfpInitMediaの前に設定をしてください
RFP.rfpInitMedia("your_media_id")
}
[設定]
> [一般]
> [iPhoneストレージ]
> {各アプリ名}
に「video_ad_cache_rfp
」という名前で表示されます。このキャッシュファイルは、ユーザが任意のタイミングで削除可能です。rfpInitMedia
が呼び出されたタイミングで行います。このため、一時的にrfpSetVideoCacheSize
で設定したキャッシュ容量を超える可能性があります。(v2.7.0以上で利用可能)
プレイヤータップ時の動作を切り替えることができます。デフォルトはFullscreen起動です。
RFPPlayerControl.setTapActionFullscreen
RFPPlayerControl.setTapActionAdClick
RFPPlayerControl.replaceTapAction:
// Fullscreen画面の起動 (default)
playerControl.setTapActionFullscreen()
// 広告クリック
playerControl.setTapActionAdClick()
// 任意の処理
playerControl.replaceTapAction({ [weak playerControl] () -> Void in
if let weakPlayer = playerControl {
// 例: 一時停止
weakPlayer.pause()
}
})