Create a InStreamAd instance and keep its reference.
import com.intowow.sdk.InStreamAd;
private final static String PLACEMENT = "Obtain from your Intowow account manager";
private InStreamAd mInStreamAd = null;
Initialize InStreamAd
// [NOTE]
// It is recommended to initialize as early as possible.
//
Map<String, Object> adProps = new HashMap<>();
adProps.put(AdProperty.HIDE_COUNTDOWN, false);
adProps.put(AdProperty.HIDE_SPEAKER, false);
adProps.put(AdProperty.HIDE_AD_ICON, false);
adProps.put(AdProperty.SILENT_START, false);
adProps.put(AdProperty.HIDE_NON_SKIPPABLE_BUTTON, false);
adProps.put(AdProperty.HIDE_AD_COUNT_VIEW, false);
mInStreamAd = new InStreamAd(this, PLACEMENT, adProps, mContainer);
Implement InStreamAdListener to handle InStreamAd Event
mInStreamAd.setAdListener(new InStreamAd.InStreamAdListener() {
@Override
public void onAdError(InStreamAd ad, AdError error) {
// [NOTE]
// Callback if fail to load an InStream ad from Intowow SDK
//
}
@Override
public void onVideoStart(InStreamAd ad) {
}
@Override
public void onVideoEnd(InStreamAd ad) {
}
@Override
public void onAdClicked(InStreamAd ad) {
}
@Override
public void onAdMute(InStreamAd ad) {
}
@Override
public void onAdUnmute(InStreamAd ad) {
}
@Override
public void onAdImpression(InStreamAd ad) {
}
@Override
public void onProgress(InStreamAd ad, long totalDuration, long currentPosition) {
// [NOTE]
// onProgress is best for monitoring
// e.g.
//ad.getAdBreakRemainTime();
//ad.getAdRemainTime();
//ad.getCurrentAdNum();
//ad.getTotalAdNum();
//
}
@Override
public void onRequestContentPause(InStreamAd ad, int adBreakType,
long cuePointTime) {
// [NOTE]
// After onRequestContentPause, ad is ready
// and can be played after video player is paused.
//
// [Pre-roll]
// When the ad arrives late, please aware that Preroll ad
// will callback here after the content has started.
// You need to handle this situation when cuePointTime = 0.
//
if(yourMediaPlayer != null && yourMediaPlayer.isPlaying()) {
yourMediaPlayer.pause();
}
if (mInStreamAd != null) {
mInStreamAd.play();
}
}
@Override
public void onRequestContentResume(InStreamAd ad, long adRemainTime) {
// [NOTE]
// Two scenario to trigger inStreamADRequestContentResume:
// (1) Video ad is finished (adRemainTime = 0)
// --> Please stop inStreamAD and resume Video Player
// (2) Time requirement of ad break has been met (adRemainTime > 0)
// --> Resume Video Player or keep playing ad is up to you.
// If you chose to complete playing video ad, inStreamADRequestContentResume
// will be called again once ad is finished(scenario (1)).
//
//
// [Best Practice]
// onRequestContentResume is best for resume playing video
// content if InStream ad finished playing.
//
if (mInStreamAd != null && adRemainTime == 0) {
mInStreamAd.stop();
}
yourMediaPlayer.start();
}
@Override
public void onCuePointsReady(InStreamAd ad) {
// [NOTE]
// getCuePoint shall be called after onCuePointsReady
// e.g.
// ad.getCuePoints();
//
}
);
Request InStreamAd
startAutoRequestAdmust be called after InStreamAd instance is initialized
startAutoRequestAdshall be called before video content is played, otherwise ad breaks in the beginning of the video, pre-roll ad especially, will be wasted
Please called startAutoRequestAd only one time.
mInStreamAd.startAutoRequestAD();
Implement CEContentProgressProvider to update Video Content Status
isContentPlayerReady, getContentCurrentPosition and getContentTotalDurationmust be implemented otherwise InStream ad will not be served
Please read this carefully: During the time user is seeking the video, APP should always return the progress time that user start seeking instead of the current time that user has sought to. Once user stop seeking, please return the progress time that user stopped at.
mInStreamAd.setContentProgressProvider(new InStreamAd.CEContentProgressProvider() {
@Override
public long getContentCurrentPosition() {
if (yourMediaPlayer == null) {
return 0;
} else if (isSeeking) {
return mLastPosition;
}
return yourMediaPlayer.getCurrentPosition();
}
@Override
public long getContentTotalDuration() {
if (yourMediaPlayer == null) {
return 0;
}
return yourMediaPlayer.getDuration();
}
@Override
public boolean isContentPlayerReady() {
return yourMediaPlayerReady;
}
});
Release InStreamAd
InStream ad shall at least be released along with the life cycle of video content