애플리케이션 클래스 빌드
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
application.js
에서 HbbTV 방송과 상호작용하는 HbbTV 앱의 기본 클래스를 만듭니다. 이 클래스는 broadcastAppManager
및 broadcastContainer
와 상호작용합니다. 유사한 클래스의 예는 브로드캐스트 a/v 객체 처리를 참고하세요.
이 기본 HbbTV 앱을 수정하여 IMA 스트림을 요청하고 광고 시점 이벤트에 응답합니다.
애플리케이션 초기화
application.js
에서 애플리케이션 클래스를 초기화하고 튜토리얼 브로드캐스트 a/v 객체 처리에 따라 broadcastAppManager
및 broadcastContainer
를 설정합니다.
그런 다음 새 VideoPlayer
및 AdManager
객체를 시작합니다.
IMA 스트림 요청하기
HbbTVApp.onPlayStateChangeEvent()
메서드에서 앱이 PRESENTING_PLAYSTATE
로 전환되는 것에 대한 응답으로 스트림 요청을 합니다. 이 접근 방식은 AD_BREAK_EVENT_ANNOUNCE
이벤트에 응답하여 광고 애드온 매니페스트를 로드하도록 앱을 준비합니다.
기기에서 브로드캐스트 컨테이너 PlayStateChange
이벤트를 올바르게 내보내지 않으면 setInterval()
함수를 사용하여 재생 상태 변경을 확인합니다.
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);
}
…
HbbTV 스트림 이벤트 수신
광고 시점 이벤트 adBreakAnnounce
, adBreakStart
, adBreakEnd
를 수신하는 HbbTVApp.onStreamEvent()
메서드를 만듭니다.
HbbTV 스트림 이벤트 처리
HbbTV 스트림 이벤트를 처리하려면 다음 단계를 완료하세요.
adBreakAnnounce
이벤트에 응답하여 광고 모음 매니페스트를 로드하려면 HbbTVApp.onAdBreakAnnounce()
메서드를 만듭니다.
광고 시점에 광고 스트림 재생으로 전환하려면 HbbTVApp.onAdBreakStart()
메서드를 만듭니다.
콘텐츠 브로드캐스트로 돌아가려면 HbbTVApp.onAdBreakEnd()
메서드를 만듭니다.
이제 HbbTV 앱에서 IMA SDK 광고 애드팟을 요청하고 표시합니다. 앱을 완료된 샘플 앱과 비교하려면 GitHub의 IMA HbbTV 샘플을 참고하세요.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-31(UTC)
[null,null,["최종 업데이트: 2025-08-31(UTC)"],[[["\u003cp\u003eThis guide details how to integrate the IMA SDK into an HbbTV application to enable dynamic ad insertion, building upon a pre-existing ads manager class.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves initializing the application, making an IMA stream request when the broadcast begins, and listening for HbbTV stream events signaling ad breaks.\u003c/p\u003e\n"],["\u003cp\u003eSpecific event handlers (\u003ccode\u003eonAdBreakAnnounce\u003c/code\u003e, \u003ccode\u003eonAdBreakStart\u003c/code\u003e, \u003ccode\u003eonAdBreakEnd\u003c/code\u003e) manage ad pod loading, ad playback, and the seamless transition back to broadcast content.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the provided code snippets for implementation guidance and to the IMA HbbTV sample on GitHub for a complete working example.\u003c/p\u003e\n"]]],[],null,["| **Note:** Before moving forward with this guide, you must complete the steps in [Create the ads manager class](/ad-manager/dynamic-ad-insertion/sdk/html5/hbbtv-ads-manager).\n\nIn `application.js`, create the main class for your HbbTV app that interacts\nwith the HbbTV broadcast. This class interacts with the `broadcastAppManager`\nand `broadcastContainer`. For an example of a similar class, see\n[Handling the broadcast a/v object](//developer.hbbtv.org/tutorials/handling-the-broadcast-av-object/).\n\nModify this base HbbTV app to request an IMA stream and respond to ad break\nevents.\n\nInitialize the application\n\nInitialize the application class in `application.js`, set up the\n`broadcastAppManager`, and `broadcastContainer` following the tutorial,\n[Handling the broadcast a/v object](//developer.hbbtv.org/tutorials/handling-the-broadcast-av-object/).\nAfterwards, initiate new `VideoPlayer` and `AdManager` objects. \n\n /** Main HbbTV Application. */\n var HbbTVApp = function() {\n this.broadcastAppManager = document.getElementById('broadcast-app-manager');\n this.broadcastContainer = document.getElementById('broadcast-video');\n\n this.playState = -1; // -1 as null play state.\n\n try {\n this.applicationManager =\n this.broadcastAppManager.getOwnerApplication(document);\n this.applicationManager.show();\n this.broadcastContainer.bindToCurrentChannel();\n this.subscribedToStreamEvents = false;\n this.broadcastContainer.addEventListener(\n 'PlayStateChange', this.onPlayStateChangeEvent.bind(this));\n\n debugView.log('HbbTVApp: App loaded');\n this.videoPlayer = new VideoPlayer();\n this.videoPlayer.setOnAdPodEnded(this.resumeBroadcast.bind(this));\n } catch (e) {\n debugView.log('HbbTVApp: No HbbTV device detected.');\n return;\n }\n\n this.adManager = new AdManager(this.videoPlayer);\n }; \n https://github.com/googleads/googleads-ima-html5-dai/blob/d215db4a053d12c842e899da470684142ff732f6/hbbtv/application.js#L39-L64\n\nMake an IMA stream request\n\nIn the `HbbTVApp.onPlayStateChangeEvent()` method, make a stream request in\nresponse to the app switching to the `PRESENTING_PLAYSTATE`. This approach\nprepares your app to load the ad pod manifest in response to an\n`AD_BREAK_EVENT_ANNOUNCE` event. \n\n if (!this.subscribedToStreamEvents &&\n this.broadcastContainer.playState == PRESENTING_PLAYSTATE) {\n this.subscribedToStreamEvents = true;\n this.broadcastContainer.addStreamEventListener(\n STREAM_EVENT_URL, 'eventItem', function(event) {\n this.onStreamEvent(event);\n }.bind(this));\n debugView.log('HbbTVApp: Subscribing to stream events.');\n this.adManager.requestStream(NETWORK_CODE, CUSTOM_ASSET_KEY);\n } \n https://github.com/googleads/googleads-ima-html5-dai/blob/d215db4a053d12c842e899da470684142ff732f6/hbbtv/application.js#L75-L84\n\nIf your device doesn't correctly emit the broadcast container `PlayStateChange`\nevent, use the `setInterval()` function to check for playstate changes: \n\n setInterval(function() {\n if (!subscribedToStreamEvents &&\n this.broadcastContainer.playState == PRESENTING_PLAYSTATE) {\n subscribedToStreamEvents = true;\n this.broadcastContainer.addStreamEventListener(\n STREAM_EVENT_URL, 'eventItem', function(event) {\n this.onStreamEvent(event);\n }.bind(this));\n debugView.log('Subscribing to stream events');\n this.adManager.requestStream(NETWORK_CODE, CUSTOM_ASSET_KEY);\n }\n ...\n\nListen to HbbTV stream events\n\nCreate the `HbbTVApp.onStreamEvent()` method to listen to the ad break events\n`adBreakAnnounce`, `adBreakStart`, and `adBreakEnd`: \n\n /**\n * Callback for HbbTV stream event.\n * @param {!Event} event Stream event payload.\n */\n HbbTVApp.prototype.onStreamEvent = function(event) {\n var eventData = JSON.parse(event.text);\n var eventType = eventData.type;\n if (eventType == AD_BREAK_EVENT_ANNOUNCE) {\n this.onAdBreakAnnounce(eventData);\n } else if (eventType == AD_BREAK_EVENT_START) {\n this.onAdBreakStart(eventData);\n } else if (eventType == AD_BREAK_EVENT_END) {\n this.onAdBreakEnd(eventData);\n }\n }; \n https://github.com/googleads/googleads-ima-html5-dai/blob/d215db4a053d12c842e899da470684142ff732f6/hbbtv/application.js#L94-L108\n\nHandle the HbbTV stream events\n\nTo handle the HbbTV stream events, complete the following steps:\n\n1. To load the ad pod manifest in response to the `adBreakAnnounce` event,\n create the `HbbTVApp.onAdBreakAnnounce()` method:\n\n /**\n * Callback function on ad break announce stream event.\n * @param {!Event} event HbbTV stream event payload.\n */\n HbbTVApp.prototype.onAdBreakAnnounce = function(event) {\n var eventType = event.type;\n var eventDuration = event.duration;\n var eventOffset = event.offset;\n debugView.log(\n 'HbbTV event: ' + eventType + ' duration: ' + eventDuration +\n 's offset: ' + eventOffset + 's');\n this.adManager.loadAdPodManifest(NETWORK_CODE, CUSTOM_ASSET_KEY, eventDuration);\n }; \n https://github.com/googleads/googleads-ima-html5-dai/blob/d215db4a053d12c842e899da470684142ff732f6/hbbtv/application.js#L138-L150\n\n2. To switch to ad stream playback during ad breaks, create the\n `HbbTVApp.onAdBreakStart()` method:\n\n /**\n * Callback function on ad break start stream event.\n * @param {!Event} event HbbTV stream event payload.\n */\n HbbTVApp.prototype.onAdBreakStart = function(event) {\n debugView.log('HbbTV event: ' + event.type);\n if (!this.videoPlayer.isPreloaded()) {\n debugView.log('HbbTVApp: Switch aborted. ' +\n 'The ad preloading buffer is insufficient.');\n return;\n }\n this.stopBroadcast();\n this.videoPlayer.play();\n }; \n https://github.com/googleads/googleads-ima-html5-dai/blob/d215db4a053d12c842e899da470684142ff732f6/hbbtv/application.js#L154-L167\n\n3. To return to the content broadcast, create the `HbbTVApp.onAdBreakEnd()`\n method:\n\n /**\n * Callback function on ad break end stream event.\n * @param {!Event} event HbbTV stream event payload.\n */\n HbbTVApp.prototype.onAdBreakEnd = function(event) {\n debugView.log('HbbTV event: ' + event.type);\n this.videoPlayer.stop();\n this.resumeBroadcast();\n }; \n https://github.com/googleads/googleads-ima-html5-dai/blob/d215db4a053d12c842e899da470684142ff732f6/hbbtv/application.js#L171-L179\n\nYou're now requesting and displaying IMA SDK ad pods in your HbbTV\napp. To compare your app with a completed sample app, see the\n[IMA HbbTV sample on GitHub](//github.com/googleads/googleads-ima-html5-dai/tree/main/hbbtv)."]]