Typically for a web application to play content with the Server-Side Ad Insertion (SSAI) service provided by IMA DAI, first it creates an instance of StreamManager – to request and manage the video stream with server-side ads inserted, as shown in the following example:
<!DOCTYPE html> <html lang="en"> <head> ... <script src="//imasdk.googleapis.com/js/sdkloader/ima3_dai.js"></script> </head> ... <script> var stream_manager = new google.ima.dai.api.StreamManager(media_element, ad_ui_element); stream_manager.addEventListener(google.ima.dai.api.StreamEvent.Type.LOADED, function(event) { my_player.load(event.getStreamData().url); }); var stream_request = new google.ima.dai.api.LiveStreamRequest(); stream_request.assetKey = ...; stream_request.apiKey = ...; stream_manager.requestStream(stream_request); </script>
If the stream request is successful, through the listener to the IMA DAI LOADED
stream event the URL for playing video (with server-side ads inserted) is received and loaded into the player for content/ads presentation.
To an uninformed player or player data collector, the server-side inserted ads are indistinguishable from real contents under the same video stream. For a Datazoom collector to identify these ads and report ad data points accordingly, it must be given access to the StreamManager instance in order to derive the extra information needed for handling SSAI ads. This is discussed in the next section.
Attach the StreamManager
As in most Datazoom collector integrations, as soon as a player instance is created, a Datazoom collector context is created in order to collect data for this specific player. Now, we must perform one additional context method call to give the Datazoom collector context the access to the StreamManager.
The context method is named attachImaDaiStreamManager()
and it should be called as soon as the StreamManager is created, as demonstrated in the following example:
my_player = createPlayer(); datazoom_context = datazoom.createContext(my_player); ... var stream_manager = new google.ima.dai.api.StreamManager(media_element, ad_ui_element); datazoom_context.attachImaDaiStreamManager(stream_manager); stream_manager.addEventListener(google.ima.dai.api.StreamEvent.Type.LOADED, function(event) { my_player.load(event.getStreamData().url); }); var stream_request = new google.ima.dai.api.LiveStreamRequest(); stream_request.assetKey = ...; stream_request.apiKey = ...; stream_manager.requestStream(stream_request);
That’s it. The Datazoom collector is now provided with the required access to gather SSAI ad related information.
Normally the IMA DAI SDK relies on the application to forward timed metadata from the player to the IMA DAI SDK. However, if the Datazoom collector is given access to the StreamManager as demonstrated above, we will function as a bridge between the player and IMA DAI SDK to meet these integration requirements, so the application can be spared from the extra effort.
Register SDK Event Callbacks to Update UI for SSAI Ads
The application may register callback functions to be invoked by Datazoom collector SDK when the current playhead enters or leaves the time span of a SSAI ad, as demonstrated below:
datazoom.on(datazoom.sdkEvent.AD_START, function(context, ad) { // entering the time span of a SSAI ad -- switch player UI to // make it appropriate for ads, such as disabling trick play controls }); datazoom.on(datazoom.sdkEvent.AD_END, function(context) { // leaving the time span of a SSAI ad -- restore player UI back to normal });
In the sample code above, the Datazoom collector context corresponding to the player is passed as the context
argument. Besides, the native ad object (as defined by IMA here) is passed as the ad
argument – it contains useful information such as the ad’s skip offset value.
Comments
0 comments
Article is closed for comments.