Skip to main content

Ad policy

Ad policies are rule sets that you can enforce while handling seek events with media containing adverts. The following are the rules and behaviors defined.

PlaybackFastForwardRule

Ad playback policy applicable with fast forward operation.

RuleDescription
TRICK_FW_PLAY_ALLEnforces the rule that the player replays all the ad breaks that were leaped over by the user during trick mode fast forward operation. This is the default rule.
TRICK_FW_PLAY_FIRSTEnforces the rule that the player replays only the first ad break that was leaped over by the user during trick mode fast forward operation.
TRICK_FW_PLAY_LASTEnforces the rule that the player replays only the last ad break that was leaped over by the user during trick mode fast forward operation.
TRICK_FW_SKIP_ALLEnforces the rule that the player skips all the ad breaks that were leaped over by the user during trick mode fast forward operation.

PlaybackRewindRule

Ad playback policy applicable with rewind operation.

RuleDescription
TRICK_RW_PLAY_ALLEnforces the rule that the player replays all the ad breaks that were leaped over by the user during trick mode rewind operation. This is the default rule.
TRICK_RW_PLAY_FIRSTEnforces the rule that the player replays only the first ad break that was leaped over by the user during trick mode rewind operation.
TRICK_RW_PLAY_LASTEnforces the rule that the player replays only the last ad break that was leaped over by the user during trick mode rewind operation.
TRICK_RW_SKIP_ALLEnforces the rule that the player skips all the ad breaks that were leaped over by the user during trick mode rewind operation.

PlaybackInterruptedRule

Ad playback policy applicable with playback interruption.

RuleDescription
INTERRUPT_SKIPEnforces the rule that the player skips the ad break that was interrupted (for example, by a phone call).
INTERRUPT_RESTARTEnforces the rule that the player replays the ad break that was interrupted (for example, by a phone call).
INTERRUPT_RESUMEEnforces the rule that the player resumes the ad break that was interrupted (for example, by a phone call). This is the default rule.

PlaybackAutoSeekRule

Ad playback policy applicable with playback starting from an initial playback position.

RuleDescription
AUTO_SEEK_SKIP_ALLEnforces the rule that the player starts the content without forcing the user to watch any ads that are available from the start of the content to the bookmarked time.
AUTO_SEEK_PLAY_PREROLLEnforces the rule that the player forces the user to watch the PREROLL ads, while any MIDROLL ads that are available from the start of the content to the bookmarked time are skipped.
AUTO_SEEK_PLAY_MIDROLLEnforces the rule that the player forces a user to watch at least one MIDROLL ad, while the PREROLL ads are skipped. Whether the user has to watch all triggered MIDROLL ads, or only one, is determined by the PlaybackFastForwardRule policy value.
AUTO_SEEK_PLAY_ALLEnforces the rule that the player forces a user to watch the PREROLL ads, then one or more MIDROLL ads. Whether the user has to watch all triggered MIDROLL ads, or only one, is determined by the PlaybackFastForwardRule policy value. This is the default rule.

PlaybackRepeatedRule

Ad playback policy applicable with repeated ad playback in a single playback session.

RuleDescription
REPEAT_ALWAYS_PLAYEnforces the rule that the player repeatedly plays the ad break, with a given ID, in a single playback session whenever the ad break is triggered.
REPEAT_PLAY_ONCEEnforces the rule that the player plays the ad break, with a given ID, only once in a single playback session whenever the ad break is triggered. This is the default rule.

AdPolicy with SSAI

You can set ad policy rules while initializing YoSession.

// create YospaceAdsPlaybackPolicy
val playbackPolicy: AdPlaybackPolicy = YospaceAdsPlaybackPolicy()
playbackPolicy.setAdPlaybackRules(
AdPlaybackPolicy.TRICK_FW_PLAY_ALL,
AdPlaybackPolicy.TRICK_RW_PLAY_ALL,
AdPlaybackPolicy.INTERRUPT_RESUME,
AdPlaybackPolicy.AUTO_SEEK_PLAY_ALL,
AdPlaybackPolicy.REPEAT_PLAY_ONCE
)

// Create YospaceAdsSession
val yoPlaybackMode = playbackMode?.toYospaceSessionPlaybackMode()
val initData = YospaceSessionInitializationData(
contentURL,
yoPlaybackMode,
isValidationRequired = true
)
val yospaceAdsSession = YospaceAdsPlayerFactory.createYospaceAdsSession(initData)

// initialise ad session with the AdPlaybackPolicy for VOD
yospaceAdsSession.initializeVODSession() { sessionInitResult ->
when (sessionInitResult) {
is Result.Success -> {
val playbackURL = sessionInitResult.value.url
// create ad player for playback
val yoPlayer = YospaceAdsPlayerFactory.createYospaceAdsPlayer(
player,
playbackPolicy,
yospaceAdsSession
)
}
is Result.Failure -> {
val error = sessionInitResult.value
// handle error
}
}
}

// initialise ad session with the AdPlaybackPolicy for Live
val result = yospaceAdsSession.computePlaybackURLForLiveSession { _, error ->
// handle error
}) {
is Result.Success -> {
val playbackURL = result.value.url
// create ad player for playback
val yoPlayer = YospaceAdsPlayerFactory.createYospaceAdsPlayer(
player,
playbackPolicy,
yospaceAdsSession
)
}
is Result.Failure -> {
val error = result.value
// handle error
}
}

Yospace fallback handling

The yospaceAdsSession.initializeLiveSession() and yospaceAdsSession.initializeVODSession() methods resolve with PlaybackUrl, SessionStatus, and Reason for Failure, which provides detailed information on each sessionState.

yospaceSessionStateStatusPlayback UrlReason
INITIALISEDsuccess{ContentURL with yospace}NA
NO_ANALYTICSfallback{fallback url from yospace}Yospace Session initialization Failed with Status : fallback and errorCode : 0
FAILEDerror{origin url}Yospace Session initialization Failed with Status : error and errorCode : -1

yospaceAdsSession.initializeVODSession() { sessionInitResult ->
when (sessionInitResult) {
is Result.Success -> {
val playbackURL = sessionInitResult.value.url
// create ad player for playback
val yoPlayer = YospaceAdsPlayerFactory.createYospaceAdsPlayer(
player,
playbackPolicy,
yospaceAdsSession
)
// This can be used for reporting yospace status and reason for fallback/error.
val playbackURL = sessionInitResult.value.url
val sessionState = sessionInitResult.value.sessionState
val reason = sessionInitResult.value.reason
}
is Result.Failure -> {
val error = sessionInitResult.value
// handle error
}
}
}