Ad formats: Instream

Instream ads are video advertisements that play before, during, or after video content, typically appearing over the video player environment.

Add dependencies

To integrate the RTB-Stack instream module, add the following dependency to your app-level build.gradle file:

dependencies {
   implementation 'com.rtb-stack.sdk:instream:0.1.0.0'
}

Instream Ad Setup

Setting up an instream ad involves several key steps:

  1. Instantiate the VideoAd class.
  2. Load an Instream ad.
  3. When ready, display the instream ad within a container.
  4. After the video ad playback is complete, resume your video content.

Let’s look at these steps in detail.

Load Ad

Create a VideoAd instance and pass a Context and TagId to its constructor:

SDKSettings.setRequestBaseUrl("Your endpoint request url");
VideoAd videoAd = new VideoAd(this, "Your custom tag id");

Note:

  • Endpoint Request URL: You can obtain an Endpoint Request URL from the Edit Endpoint window as described here
  • Custom Tag ID: Assign a random string as a Tag ID for tracking and reporting purposes. For example, "Instream_Video_MidRoll_15s".

Set VideoAdLoadListener that will inform you about a successful load or an error:

videoAd.setAdLoadListener(new VideoAdLoadListener() {
   @Override
   public void onAdLoaded(VideoAd videoAd) {
   }

   @Override
   public void onAdRequestFailed(VideoAd videoAd, ResultCode errorCode) {
   }
});

Call VideoAd.loadAd() to start loading the ad:

videoAd.loadAd();

Show Video Ad in Container

Show the instream ad at some point in your video content. The instream ad will be displayed on top of the passed container. The container should be a FrameLayout or a RelativeLayout and should have the same size as the video content:

if (videoAd.isReady()) {
   // Play instream ad inside the container
   videoAd.playAd("YOUR_CONTAINER");
}

Listen for Video Events

Set VideoAdPlaybackListener to receive video playback events. In onAdCompleted() method, resume your video content:

videoAd.setVideoPlaybackListener(new VideoAdPlaybackListener() {

   @Override
   public void onAdPlaying(final VideoAd videoAd) {
   }

   @Override
   public void onQuartile(VideoAd view, Quartile quartile) {
   }

   @Override
   public void onAdCompleted(VideoAd view, PlaybackCompletionState playbackState) {
       // start playing your video content
   }

   @Override
   public void onAdMuted(VideoAd view, boolean isMute) {
   }

   @Override
   public void onAdClicked(VideoAd adView) {
   }

   @Override
   public void onAdClicked(VideoAd videoAd, String clickUrl) {
   }
});

VideoAd Options

VideoAd allows for configuring various options related to how an ad’s URL is handled:

  • Open the URL in an in-app browser (WebView):
  • videoAd.setClickThroughAction(ANClickThroughAction.OPEN_SDK_BROWSER);
  • Open the URL in the device browser:
  • videoAd.setClickThroughAction(ANClickThroughAction.OPEN_DEVICE_BROWSER);
  • Return the URL in the AdListener.onAdClicked() callback:
  • videoAd.setClickThroughAction(ANClickThroughAction.RETURN_URL);

Ad Controls:

  • Show/hide click-through control: videoAd.showClickThroughControl(); or videoAd.hideClickThroughControl();
  • Show/hide volume control: videoAd.showVolumeControl(); or videoAd.hideVolumeControl();
  • Show/hide skip button: videoAd.showSkip(); or videoAd.hideSkip();

Miscellaneous:

  • Send content ID: videoAd.setContentId("YOUR_CONTENT_ID");.
  • Retrieve creative details: videoAd.getCreativeId();, videoAd.getCreativeWidth();, videoAd.getCreativeHeight();.

Updated on October 31, 2024