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
adBreakAnnounce
event, 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.