Support for video advertising

※ Currently video advertisements can only be used by limited partners

Components provided with the video advertisement SDK

  • RFPPlayerControl
    • This is the UI view displaying the video player. This provides a function to control the video. Insert any UIView as a Subview.

Judgment of video advertisement

In the case of a video advertisement, RFPInstreamInfoModel.isVideo() is returned as true. This can be used to judge whether it is a video advertisement or not.

Delegate method used with video advertisements

There are two RFPInstreamAdLoaderDelegate methods used with video advertising.

  • viewControllerForPresentingModalView

    • Return the calling source ViewController. This is compulsory when playing back video advertisements.
  • readyToPlay(with playerControl: RFPPlayerControl!)

    • Called when playback preparation is complete. Note that this is not played back even if playerControl.play() is executed before preparations are complete.

Acquiring video advertisements

instreamAdLoader.getVideoControl(withFrame:infoModel:) Can use to acquire RFPPlayerControl.

Specifying viewControllerForPresentingModalView

In the case of Video playback, be sure to specify RFPInstreamAdLoaderDelegate.viewControllerForPresentingModalView.

This is necessary when switching the video to Fullscreen.

For the return value, specify the calling source UIViewController.

func rfpInstreamAdLoaderDidFinishLoadingAd(withReturn instreamAdLoader: RFPInstreamAdLoader!, instreamInfoModels: [Any]!) {

    // Acquiring In-Feed advertisement information
    for model: RFPInstreamInfoModel in instreamInfoModels as! [RFPInstreamInfoModel] {
        if (model.isVideo()) {
            // Acquiring RFPPlayerControl
            let playerControl = instreamAdLoader.getVideoControl(withFrame: containerView.bounds, infoModel: model)!
            // Do not set other than playerUiView
            containerView.subviews.forEach { subview in
                subview.removeFromSuperview()
            }
            containerView.addSubview(playerControl)
        }
    }
}

// ※ Mandatory in case of video advertisement playback
func viewControllerForPresentingModalView() -> UIViewController! {
    return self
}

Playback preparation complete

When playback preparation is complete, RFPInstreamAdLoaderDelegate.readyToPlay(with:) is called.

The initial state of the player is a paused state.

func readyToPlay(with playerControl: RFPPlayerControl!) {
    // Playback
    playerControl.play()
    // Pause
    playerControl.pause()
}

Playing the video

Start playback using RFPPlayerControl.play().

It is possible to pause using RFPPlayerControl.pause().

    // Playback
    playerControl.play()
    // Pause
    playerControl.pause()

End playback

(Can be used on v2.7.0 or later)

When playback is ended,RFPInstreamAdLoaderDelegate.didPlayToEndTime(with:) is called.

func didPlayToEndTime(with playerControl: RFPPlayerControl!) {
    // for playback ended
}

Cache settings

(Can be used on v2.5.0 or later, iOS11 or later)

In the RFP, video advertisements are cached to a certain extent in the internal storage of the terminal (HLS download storage), and this reduces communication volume and improves the video advertisement playback response.

The setting values recommended by the RFP are used for the cache capacity. This value can be changed from the app side.

When changing the cache capacity, use the RFP.rfpSetVideoCacheSize(_:) to set the cache capacity.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    // Acquire current setting value
    let size = RFP.rfpGetVideoCacheSize()

    //Set the video cache to 100 MB.
    RFP.rfpSetVideoCacheSize(100);

    // Disable the video cache
    RFP.rfpSetVideoCacheSize(0);

    // ※ Be sure to set the rfpSetVideoCacheSize before rfpInitMedia
    RFP.rfpInitMedia("your_media_id")
}

Points to note when setting the cache

*In iOS11 or later, the cached video advertisements are displayed with the name”video_ad_cache_rfp” under ‘[Settings]’>’[General]’>[iPhone storage]>{each app name}. This cached file can be deleted at any time by the user. * The cache is cleared at the time rfpInitMedia is called. For this reason, the cache capacity temporarily set in rfpSetVideoCacheSize may be exceeded.

Setting the tap action

(Can be used on v2.7.0 or later)

Set action when player is tapped.The default is Fullscreen.

  • RFPPlayerControl.setTapActionFullscreen
    • Start Fullscreen. This is the default behavior.
  • RFPPlayerControl.setTapActionAdClick
    • It becomes the operation of ad click. Playback will be stopped.
  • RFPPlayerControl.replaceTapAction:
    • You can set arbitrary processing.
// for Fullscreen
playerControl.setTapActionFullscreen()

// for Ad click
playerControl.setTapActionAdClick()

// for arbitrary processing
playerControl.replaceTapAction({ [weak playerControl] () -> Void in
    if let weakPlayer = playerControl {
        // ex) pause
        weakPlayer.pause()
    }
})