Skip to main content

Server Side Ad Insertion

The FLAdvertisingYospace library integrates with Yospace to offer Server Side Ad Insertion capability for both VOD and Live.

Setup

Yospace AdManagement framework must be embedded with app.

note

Please use the Yospace framework version shipped with the Quickplay libraries.

Wiring Authorization Response

Once an asset is authorized for Playback (refer Authorize Playback for an Asset), the authorization response indicates if the content is ad enabled. The Ad player must be setup only when this flag is enabled.

NameDescription
ssaiEnabledIndicates whether the content is Ad enabled

Create YoAdSession

Create a YoSessionInitData initialization data with content url, playback mode. Create YoAdSession using the init data created.

let initData = FLAdvertisingYospaceFactory.yoSessionInitData(contentUrl: contentUrl, playbackMode: .live)
// create ad session
let yoAdSession = FLAdvertisingYospaceFactory.adSession(initData: initData)

PlaybackMode

The following playback modes are currently supported.

NameDescription
LiveRepresents Live mode
LiveRestartRepresents Live restart mode
LiveCatchupRepresents Live catchup mode
VodRepresents VOD mode

Initialize YoAdSession

Initialize the session to obtain playback url from the ad session instance. The session once sucessfully initialized would return the actual playbackUrl to use.

// initialize ad session with callback to handle session result
yoAdSession.initialize { result in
switch result {
case let .success(playbackUrl):
// create ad player for playback
case let .failure(error):
// handle error
}
}
note

For ad enabled contents (ssaiEnabled), the authorization service returns a VMAP playlist as contentUrl, but returns a regular manifest for Live Linear playback.

Create Content Player and Ad Player

Create a player using the playback url received on session initialisation. Create the ad Player using main content Player and YoAdSession.

// create player using the playback url obtained from ad session initialisation
if let playbackURL = URL(string: playbackUrl) {
let avURLAsset = AVURLAsset(url: playbackURL)
let player = FLPlatformPlayerFactory.player(asset: avURLAsset)
// Create ad player with player and ad session
let adPlayer = FLAdvertisingYospaceFactory.adPlayer(player: player, yoAdSession: yoAdSession)
}

This ad player could be used like conventional player from FLPlayer library for playback.

Listening to Ad Delegate Methods

The client can set delegate on ad player and listen to ad events to track the state of ad playback and implement custom UIs. The AdPlayer invokes the following ad delegate methods:

/// Called on ad playback failure
func adPlayer(ad: Ad?, didFailWith error: Error)

/// Called when cue points are available
func adPlayerDidProvide(cuepoints: [Int])

/// Called on ad break start
func adPlayerDidStart(adBreak: AdBreak)

/// Called on ad start
func adPlayerDidStart(ad: Ad)

/// Called on ad playback progress change
func adPlayer(ad: Ad?, didChange progress: TimeInterval)

/// Called on ad playback buffer state change
func adPlayer(ad: Ad?, didChangeBuffer isBuffering: Bool)

/// Called on occurance of ad track event
func adPlayer(ad: Ad?, didTrack event: AdTrackingEvent)

/// Called on ad end
func adPlayerDidEnd(ad: Ad)

/// Called on ad break end
func adPlayerDidEnd(adBreak: AdBreak)

Ad Metadata

AdBreak

Represents an ad break object.

PropertyTypeDescription
positionAdPositionThe position of the ad break, can be on of preroll, midroll or postroll
startTimeTimeIntervalThe start position in seconds
durationTimeIntervalThe duration of the ad break, in seconds
totalAdsIntTotal number of adverts in the ad break

Represents an advert object.

PropertyTypeDescription
adIdStringThe identifier of the advert
sequenceIntThe sequence of the advert
durationTimeIntervalThe duration of the advert in seconds
isSkippableBoolIndicates if the ad is skippable
adBreakAdBreakThe ad break which the advert belongs to

Open Measurement

The client can set open measurement event delegate on Ad Player to listen to events that would provide ad vertification metadata which can be used for Open Measurement integration.

The delegate only provides metadata and resources for open measurement and the client must integrate open measurement on the app. Please refer IAB Open Measurement for complete integtration of Open Measurement SDK.

The following are the delegate methods


/// Called when the ad verification should be started.
/// - Parameters:
/// - adVerification: The list of `AdVerification` instances.
/// - vastProperties: The `VASTProperties` instance.
/// - adVideoProperties: The `AdVideoProperties` instance.
func adVerificationDidStart(adVerification: [AdVerification]?, vastProperties: VASTProperties, adVideoProperties: AdVideoProperties)

/// Called when the ad verification should be completed.
func adVerificationDidEnd()

/// Called when an ad tracking event is signalled.
/// - Parameter adTrackingEvent: The `AdTrackingEvent` identifier.
func adDidTrackEvent(event: AdTrackingEvent)

Verification Metadata

AdVerification

Represents an ad verification object.

PropertyTypeDescription
vendorKeyStringThe unique identifier of the verification provider
verificationParameterStringThe parameters which the verification provider script is expecting for the Ad Session
verificationResourceArray of VerificationResourceThe collection of VerificationResources
VerificationResource

Represents an ad verification resource object.

PropertyTypeDescription
nameStringThe name of the node for the ad verification resource
valueStringThe value of the node for the ad verification resource
attributesDictionaryDictionary instance of attributes of the node for the ad verification resource.

For example, lets say the ad response has the following ad verification metadata :

  <AdVerifications>
<Verification vendor=“iabtechlab.com-omid”>
<JavaScriptResource apiFramework=“omid” browserOptional=“true”>
<![CDATA[https://server.com/omid-validation-verification-script-v1.js]]>
</JavaScriptResource>
<VerificationParameters>
<![CDATA[parameterstring]]>
</VerificationParameters>
</Verification>
</AdVerifications>

In the example above:

VASTProperties

Represents a VAST properties object.

PropertyTypeDescription
skipOffsetTimeIntervalThe number of seconds before the skip button is presented
isAutoPlayBoolWhether the player will auto-play content
adPositionAdPositionThe position of the ad break, can be on of preroll, midroll or postroll
adSystemStringThe source ad server of the advert
AdTitleStringThe common name of the advert
adServingIdstringAn identifier used to compare impression-level data across systems
creativeIdStringCreativeId of the advert
categoryStringCategory of the advert content
descriptionStringThe longer description of the advert
advertiserStringAdvertiser name
pricingStringPricing element of the advert
surveyStringAn URI to any resource file having to do with collecting survey data
expiresStringNumber of seconds in which the ad is valid for execution
industryIconsArray of IndustryIconThe list of IndustryIcon instances
extensionsExtensionsThe custom VAST extensions properties
IndustryIcon

This part of the VAST response contains information about industry icons. Encapsulates the data from the <Icon> element of a VAST document. It is a graphic that overlays a small portion of the advert's video and is sometimes clickable.

PropertyTypeDescription
programStringThe program represented in the icon (e.g. "AdChoice, IndustryIcon")
widthStringThe width of the icon asset
heightStringThe height of the icon asset
xPositionStringThe x-coordinate of the top, left corner of the icon asset relative to the ad display area
yPositionStringThe y-coordinate of the top left corner of the icon asset relative to the ad display area
durationStringThe duration icon should be displayed unless clicked or ad is finished playing. Provided in the format HH:MM:SS.mmm or HH:MM:SS where .mmm is milliseconds
offsetStringThe time of delay from when the associated linear creative begins playing to when the icon should be displayed. Provided in the format HH:MM:SS.mmm or HH:MM:SS where .mmm is milliseconds
apiFrameworkStringThe apiFramework Identifies the API needed to execute the icon resource file if applicable
altTextStringThe alternative text for the image. In an html5 image tag this should be the text for the alt attribute. This should enable screen readers to properly read back a description of the icon for visually impaired users
imageURLStringThe URL of the image file for the icon (PNG is preferred)
clickThroughURLStringThe URL of the action that occurs when a user clicks the IndustryIcon icon. In most cases,the user sees the "Ad Settings" page that the media player opens when the icon is clicked
fallbackImagesArray of IconClickFallbackImageThe list of IconClickFallbackImage instances
IconClickFallbackImage

Represents the fallback image attributes.

PropertyTypeDescription
widthStringThe width of the image asset
heightStringThe width of the image asset
altTextStringThe alternative text for the fallback image
imageURLStringThe URL of the image file for the fallback image (PNG is preferred)