In ads_manager.js
, define a wrapper class for the IMA SDK StreamManager that
makes stream requests, gets the ad pod manifest, listens to IMA stream events,
and passes emsg events to the IMA SDK.
In ads_manager.js
, the IMA HbbTV sample app sets up the following methods:
requestStream()
onStreamEvent()
onEmsgEvent()
loadAdPodManifest()
Initialize ads manager
Initialize the ads manager class and set listeners for the IMA stream events. In
this call, set the emsg event handler with the
VideoPlayer.setEmsgEventHandler()
method.
Make a request for an ad pod stream
Create the AdManager.requestStream()
method to create a PodStreamRequest
object using your Google Ad Manager network code and the stream's custom asset
key. Test your HbbTV app using the IMA sample DASH pod serving stream with the
following stream parameters:
- Network code:
'21775744923'
- Custom asset key:
'hbbtv-dash'
Listen to ad stream events
Create the AdManager.onStreamEvent()
method to handle your app's response to
the IMA stream events, STREAM_INITIALIZED
, AD_BREAK_STARTED
, and
AD_BREAK_ENDED
.
Handle ad stream metadata
To pass the emsg event info to IMA, create the AdManager.onEmsgEvent()
method
using the StreamManager.processMetadata()
method. The video player class calls
this method with the VideoPlayer.setEmsgEventHandler()
method.
Load the ad pod manifest
Create the AdManager.loadAdPodManifest()
method to preload the ad pod manifest
with the video player. Construct the manifest URL using the structure in
Method: DASH pod manifest.
The
HbbTV sample app
uses a randomly generated unique podId
. In production apps, the podId
is an
integer that starts at one, and increments by one for each ad break. Verify the
podId
is the same value for all viewers of the ad break. To get a podId
, we
recommend using the
Early ad break notifications
(EABN) API. In a production environment, include the podId
and podDuration
in the HbbTV stream event AD_BREAK_ANNOUNCE
.
Next, create the main application class for your HbbTV app that interacts with the HbbTV broadcast.