Page Summary
-
To integrate DAI into your HbbTV app, you must first create the main application class, initialize it, and set up the broadcast manager and container.
-
Make an IMA stream request within the
onPlayStateChangeEvent()method, triggered when the app switches to thePRESENTING_PLAYSTATE. -
Implement the
onStreamEvent()method to listen for ad break events such asadBreakAnnounce,adBreakStart, andadBreakEnd. -
Handle these ad break events by creating specific methods to load the ad pod manifest, switch to ad stream playback, and return to the content broadcast.
In application.js
, create the main class for your HbbTV app that interacts
with the HbbTV broadcast. This class interacts with the broadcastAppManager
and broadcastContainer
. For an example of a similar class, see Handling the broadcast a/v object
.
Modify this base HbbTV app to request an IMA stream and respond to ad break events.
Initialize the application
Initialize the application class in application.js
, set up the broadcastAppManager
, and broadcastContainer
following the tutorial, Handling the broadcast a/v object
.
Afterwards, initiate new VideoPlayer
and AdManager
objects.
Make an IMA stream request
In the HbbTVApp.onPlayStateChangeEvent()
method, make a stream request in
response to the app switching to the PRESENTING_PLAYSTATE
. This approach
prepares your app to load the ad pod manifest in response to an AD_BREAK_EVENT_ANNOUNCE
event.
If your device doesn't correctly emit the broadcast container PlayStateChange
event, use the setInterval()
function to check for playstate changes:
setInterval
(
function
()
{
if
(
!
subscribedToStreamEvents
&&
this
.
broadcastContainer
.
playState
==
PRESENTING_PLAYSTATE
)
{
subscribedToStreamEvents
=
true
;
this
.
broadcastContainer
.
addStreamEventListener
(
STREAM_EVENT_URL
,
'eventItem'
,
function
(
event
)
{
this
.
onStreamEvent
(
event
);
}.
bind
(
this
));
debugView
.
log
(
'Subscribing to stream events'
);
this
.
adManager
.
requestStream
(
NETWORK_CODE
,
CUSTOM_ASSET_KEY
);
}
…
Listen to HbbTV stream events
Create the HbbTVApp.onStreamEvent()
method to listen to the ad break events adBreakAnnounce
, adBreakStart
, and adBreakEnd
:
Handle the HbbTV stream events
To handle the HbbTV stream events, complete the following steps:
-
To load the ad pod manifest in response to the
adBreakAnnounceevent, create theHbbTVApp.onAdBreakAnnounce()method: -
To switch to ad stream playback during ad breaks, create the
HbbTVApp.onAdBreakStart()method: -
To return to the content broadcast, create the
HbbTVApp.onAdBreakEnd()method:
You're now requesting and displaying IMA SDK ad pods in your HbbTV app. To compare your app with a completed sample app, see the IMA HbbTV sample on GitHub .

