Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 690719513
  • Loading branch information
google-ima-devrel-bot authored and IMA Developer Relations committed Oct 28, 2024
1 parent ed6ed39 commit c1de215
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
17 changes: 12 additions & 5 deletions hbbtv/ads_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
limitations under the License.
*/

var POD_DURATION = 90000; // Ad pod duration in millisecond.

// [START create_ad_manager]
/**
* Wraps IMA SDK ad stream manager.
Expand Down Expand Up @@ -62,6 +60,7 @@ AdManager.prototype.requestStream = function(networkCode, customAssetKey) {
var streamRequest = new google.ima.dai.api.PodStreamRequest();
streamRequest.networkCode = networkCode;
streamRequest.customAssetKey = customAssetKey;
streamRequest.format = 'dash';
debugView.log('AdsManager: make PodStreamRequest');
this.streamManager.requestStream(streamRequest);
};
Expand Down Expand Up @@ -122,15 +121,23 @@ AdManager.prototype.onEmsgEvent = function(event) {
// [START ads_manager_load_manifest]
/**
* Creates DAI pod url and instructs video player to load manifest.
* @param {string} networkCode The network code.
* @param {string} customAssetKey The custom asset key.
* @param {number} podDuration The duration of the ad pod.
*/
AdManager.prototype.loadAdPodManifest = function() {
AdManager.prototype.loadAdPodManifest =
function(networkCode, customAssetKey, podDuration) {
if (!this.streamData) {
debugView.log('IMA SDK: No DAI pod session registered.');
return;
}

var manifestUrl = this.streamData.getStandalonePodManifestUrl(
this.getPodId(), POD_DURATION);
var MANIFEST_BASE_URL = 'https://dai.google.com/linear/pods/v1/dash/network/';
// Method: DASH pod manifest reference docs:
// https://developers.google.com/ad-manager/dynamic-ad-insertion/api/pod-serving/reference/live#method_dash_pod_manifest
var manifestUrl = MANIFEST_BASE_URL + networkCode + '/custom_asset/' +
customAssetKey + '/stream/' + this.streamData.streamId + '/pod/' +
this.getPodId() + '/manifest.mpd?pd=' + podDuration;
this.videoPlayer.preload(manifestUrl);
};
// [END ads_manager_load_manifest]
Expand Down
8 changes: 4 additions & 4 deletions hbbtv/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ var AD_BREAK_EVENT_END = 'adBreakEnd';
var NETWORK_CODE = '';
var CUSTOM_ASSET_KEY = '';

var app;
var debugView;
var app = null;
var debugView = null;

// [START create_app]
/** Main HbbTV Application. */
Expand All @@ -55,9 +55,9 @@ var HbbTVApp = function() {
debugView.log('HbbTVApp: App loaded');
this.videoPlayer = new VideoPlayer();
this.videoPlayer.setOnAdPodEnded(this.resumeBroadcast.bind(this));

} catch (e) {
debugView.log('HbbTVApp: No HbbTV device detected.');
return;
}

this.adManager = new AdManager(this.videoPlayer);
Expand Down Expand Up @@ -146,7 +146,7 @@ HbbTVApp.prototype.onAdBreakAnnounce = function(event) {
debugView.log(
'HbbTV event: ' + eventType + ' duration: ' + eventDuration +
's offset: ' + eventOffset + 's');
this.adManager.loadAdPodManifest();
this.adManager.loadAdPodManifest(NETWORK_CODE, CUSTOM_ASSET_KEY, eventDuration);
};
// [END app_ad_break_announce]

Expand Down
26 changes: 13 additions & 13 deletions hbbtv/video_player.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ var MIN_BUFFER_THRESHOLD = 10;

// [START create_video_player]
/**
* Video player wrapper class to control ad creative playback with dashjs in
* Video player wrapper class to control ad creative playback with dash.js in
* broadband.
*/
var VideoPlayer = function() {
this.videoElement = document.querySelector('video');
this.broadbandWrapper = document.getElementById('broadband-wrapper');
this.player = dashjs.MediaPlayer().create();
this.onAdPodEndedCallback;
this.onAdPodEndedCallback = null;

// Function passed in VideoPlayer.prototype.setEmsgEventHandler.
this.onCustomEventHandler;
this.onCustomEventHandler = null;
// Scope (this) passed in VideoPlayer.prototype.setEmsgEventHandler.
this.customEventHandlerScope;
this.customEventHandlerScope = null;

// Function to remove all of player event listeners.
this.playerListenerCleanup;
debugView.log('Player: Initializing dashjs');
this.cleanUpPlayerListener = null;
debugView.log('Player: Creating dash.js player');
};
// [END create_video_player]

Expand All @@ -56,8 +56,8 @@ VideoPlayer.prototype.play = function() {
/** Stops ad stream playback and deconstructs player. */
VideoPlayer.prototype.stop = function() {
debugView.log('Player: Request to stop player');
if (this.playerListenerCleanup) {
this.playerListenerCleanup();
if (this.cleanUpPlayerListener) {
this.cleanUpPlayerListener();
}
this.player.reset();
this.player.attachView(null);
Expand Down Expand Up @@ -105,8 +105,8 @@ VideoPlayer.prototype.preload = function(url) {
// [END video_player_preload]

/**
* Controls the dashjs player's own logging in the debugging console.
* @param {!Object} event dashjs log event.
* Controls the dash.js player's own logging in the debugging console.
* @param {!Object} event dash.js log event.
*/
VideoPlayer.prototype.onLog = function(event) {
if (event.level < 4) {
Expand All @@ -115,7 +115,7 @@ VideoPlayer.prototype.onLog = function(event) {
};

// [START video_player_attach_listeners]
/** Attaches event listener for various dashjs events.*/
/** Attaches event listener for various dash.js events.*/
VideoPlayer.prototype.attachPlayerListener = function() {
var playingHandler = function() {
this.onAdPodPlaying();
Expand All @@ -141,7 +141,7 @@ VideoPlayer.prototype.attachPlayerListener = function() {
this.player.on(SCHEME_ID_URI, customEventHandler);
}

this.playerListenerCleanup = function() {
this.cleanUpPlayerListener = function() {
this.player.off(
dashjs.MediaPlayer.events['PLAYBACK_PLAYING'], playingHandler);
this.player.off(dashjs.MediaPlayer.events['PLAYBACK_ENDED'], endedHandler);
Expand Down Expand Up @@ -191,7 +191,7 @@ VideoPlayer.prototype.onAdPodEnded = function() {
* @param {!Event} event The error event to handle.
*/
VideoPlayer.prototype.onAdPodError = function(event) {
debugView.log('Player: Ad Playback error from dashjs player.');
debugView.log('Player: Ad Playback error from dash.js player.');
this.stop();
if (this.onAdPodEndedCallback) {
this.onAdPodEndedCallback();
Expand Down

0 comments on commit c1de215

Please sign in to comment.