Instream ads are video advertisements that play before, during, or after video content, typically appearing over the video player environment.
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'
}
Setting up an instream ad involves several key steps:
VideoAd class.Let’s look at these steps in detail.
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:
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 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");
}
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 allows for configuring various options related to how an ad’s URL is handled:
videoAd.setClickThroughAction(ANClickThroughAction.OPEN_SDK_BROWSER);
videoAd.setClickThroughAction(ANClickThroughAction.OPEN_DEVICE_BROWSER);
AdListener.onAdClicked() callback:videoAd.setClickThroughAction(ANClickThroughAction.RETURN_URL);
videoAd.showClickThroughControl(); or videoAd.hideClickThroughControl();videoAd.showVolumeControl(); or videoAd.hideVolumeControl();videoAd.showSkip(); or videoAd.hideSkip();videoAd.setContentId("YOUR_CONTENT_ID");.videoAd.getCreativeId();, videoAd.getCreativeWidth();, videoAd.getCreativeHeight();.