1. Integrate Tips
Ads play in a separate video player positioned on top of the app's content video player. You control the content video playback, while the TopOn SDK is responsible for handling ad playback. Refer to the picture below:
- You can obtain the custom Tag Key-Value Map passed in during the ad load by using
ATAdInfo#getUrlTagParams()
.- The MediaVideoAd obtained through
ATMediaVideo#getMediaVideoAd()
is bound to the ATVideoAdPlayer passed in during the load.- Please refer to here for more information about the IMA SDK.
2. Load an In-Stream Video Ad
ATMediaVideoConfig.Builder atMediaVideoConfigBuilder = new ATMediaVideoConfig.Builder();
ATMediaVideo mATMediaVideo = new ATMediaVideo(activity, "your placement id",
mVideoPlayerWithAdPlayback.getVideoAdPlayer(), atMediaVideoConfigBuilder.build());
mATMediaVideo.setAdListener(new ATMediaVideoEventListener() {
@Override
public void onMediaVideoAdLoaded() { }
@Override
public void onMediaVideoAdLoadFailed(AdError adError) { }
@Override
public void onMediaVideoAdClick(ATAdInfo atAdInfo) { }
@Override
public void onMediaVideoAdResume(ATAdInfo atAdInfo) { }
@Override
public void onMediaVideoAdPause(ATAdInfo atAdInfo) { }
@Override
public void onMediaVideoAdStart(ATAdInfo atAdInfo) { }
@Override
public void onMediaVideoAdEnd(ATAdInfo atAdInfo) { }
@Override
public void onMediaVideoAdPlayError(AdError adError, ATAdInfo atAdInfo) { }
@Override
public void onMediaVideoAdSkiped(ATAdInfo atAdInfo) { }
@Override
public void onMediaVideoAdTapped(ATAdInfo atAdInfo) { }
@Override
public void onMediaVideoAdProgress(float v, double v1) { }
});
//IMA Event Listener
mATMediaVideo.setIMAEventListener(new OnIMAEventListener() {
@Override
public void onEvent(Object adEvent) { }
});
mATMediaVideo.loadAd();
3. Show an In-Stream Video Ad
⚠️Notes
- Before showing VMAP ads, you need to call
MediaVideoAd#setContentProgressProvider(Object contentProgressProvider)
to pass in the IMA SDK's ContentProgressProvider, otherwise it will affect theshowing of VMAP ads.- Before displaying MediaVideoAd, you need to call
MediaVideoAd#setContainer(ViewGroup container)
to pass in the ad display container. This container is recommended to overlay on top of the PlayerView to avoid affecting ad clicks.- VMAP ads need to wait until the IMA AD_BREAK_READY Event is triggered before you can call
MediaVideoAd#start()
to display the ad.
if (mATMediaVideo.isAdReady()) {
if (mMediaVideoAd != null) {
//destroy showing media video ad
mMediaVideoAd.onDestroy();
mMediaVideoAd = null;
}
//reset player state and content video play position
mVideoPlayerWithAdPlayback.resetInnerVideoPlayerAndParams();
ATShowConfig showConfig = new ATShowConfig.Builder().scenarioId("your scenario id").build();
mMediaVideoAd = mATMediaVideo.getMediaVideoAd(showConfig);
mVideoPlayerWithAdPlayback.setReadyToPlayContent(true);
//must setContainer(container) before start()
if (mVideoPlayerWithAdPlayback.getAdUiContainer() != null) {
mVideoPlayerWithAdPlayback.getAdUiContainer().removeAllViews();
}
//need setContainer
mMediaVideoAd.setContainer(mVideoPlayerWithAdPlayback.getAdUiContainer());
//setContentProgressProvider(VMAP need)
mMediaVideoAd.setContentProgressProvider(mVideoPlayerWithAdPlayback.getContentProgressProvider());
//Call setOnIMAEventListener to bind MediaVideoAd and OnIMAEventListener
mMediaVideoAd.setOnIMAEventListener(new OnIMAEventListener() {
@Override
public void onEvent(Object adEvent) {
/**
* do content resume、pause and start、destroy MediaVideoAd
*/
if (adEvent instanceof AdEvent) {
switch (((AdEvent) adEvent).getType()) {
case LOADED:
// AdEventType.LOADED will be fired when ads are ready to be
// played. AdsManager.start() begins ad playback. This method is
// ignored for VMAP or ad rules playlists, as the SDK will
// automatically start executing the playlist.
break;
case CONTENT_PAUSE_REQUESTED:
// AdEventType.CONTENT_PAUSE_REQUESTED is fired immediately before
// a video ad is played.
mVideoPlayerWithAdPlayback.pauseContentForAdPlayback();
break;
case CONTENT_RESUME_REQUESTED:
// AdEventType.CONTENT_RESUME_REQUESTED is fired when the ad is
// completed and you should start playing your content.
mVideoPlayerWithAdPlayback.resumeContentAfterAdPlayback();
break;
case PAUSED:
break;
case RESUMED:
break;
case AD_BREAK_READY:
// AdEventType.AD_BREAK_READY will be fired when VMAP ads are ready to be played.
// For VAMP ads, mMediaVideoAd.start() must be called after AdEventType.AD_BREAK_READY
if (mMediaVideoAd != null) {
mMediaVideoAd.start();
}
break;
case ALL_ADS_COMPLETED:
if (mMediaVideoAd != null) {
mMediaVideoAd.onDestroy();
mMediaVideoAd = null;
}
mVideoPlayerWithAdPlayback.resumeContentAfterAdPlayback();
mVideoPlayerWithAdPlayback.setReadyToPlayContent(false);
break;
case AD_BREAK_FETCH_ERROR:
// A CONTENT_RESUME_REQUESTED event should follow to trigger content playback.
if (mMediaVideoAd != null) {
mMediaVideoAd.onDestroy();
mMediaVideoAd = null;
}
mVideoPlayerWithAdPlayback.resumeContentAfterAdPlayback();
mVideoPlayerWithAdPlayback.setReadyToPlayContent(false);
break;
default:
break;
}
}
}
});
if (mMediaVideoAd != null) {
if (!mMediaVideoAd.isVMAPOffer()) {
//VAST just load start
mMediaVideoAd.start();
} else {
//VAMP wait OnIMAEventListener#AD_BREAK_READY call
}
}
}
4. Ad Scenario Statistics
Track the scene arrival rates, which are presented in the TopOn dashboard under Report -> Funnel Report -> Scenario.
- First, call
entryAdScenario()
- Then, call
isAdReady()
- Finally, call
getMediaVideoAd()
void entryAdScenario(String placementId, String scenarioId) | Enter the business scenario to track the current cache status of the ad placement. For specific usage, refer to the ad scenarios. placementId: ad placement id, you can refer to here scenarioId: ad scenario id (optional; passing null will record statistics under the default scenario) |
ATMediaVideo.entryAdScenario("your placement id", "your scenario id");
if (mATMediaVideo.isAdReady()) {
...
ATShowConfig showConfig = new ATShowConfig.Builder()
.scenarioId("your scenario id")
.build();
mMediaVideoAd = mATMediaVideo.getMediaVideoAd(showConfig);
...
}