Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 731404532
  • Loading branch information
google-ima-devrel-bot authored and IMA Developer Relations committed Feb 26, 2025
1 parent d68e117 commit 29e1fed
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 33 deletions.
17 changes: 12 additions & 5 deletions dash_js/simple/dai.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const BACKUP_STREAM =
const TEST_CONTENT_SOURCE_ID = '2559737';
const TEST_VIDEO_ID = 'tos-dash';

const NETWORK_CODE = '21775744923';
const API_KEY = null;

// StreamManager which will be used to request ad-enabled streams.
let streamManager;

Expand Down Expand Up @@ -83,9 +86,9 @@ function initPlayer() {
* Initiate stream playback.
*/
function initiatePlayback() {
requestVODStream(TEST_CONTENT_SOURCE_ID, TEST_VIDEO_ID, null);
requestVODStream(TEST_CONTENT_SOURCE_ID, TEST_VIDEO_ID, NETWORK_CODE, API_KEY);
// Uncomment line below and comment one above to request a LIVE stream.
// requestLiveStream(TEST_ASSET_KEY, null);
// requestLiveStream(TEST_ASSET_KEY, NETWORK_CODE, API_KEY);

playButton.style.display = 'none';
playButton.removeEventListener('click', initiatePlayback);
Expand All @@ -103,12 +106,14 @@ function resumePlayback() {
/**
* Requests a Live stream with ads.
* @param {string} assetKey
* @param {?string} networkCode
* @param {?string} apiKey
*/
function requestLiveStream(assetKey, apiKey) {
function requestLiveStream(assetKey, networkCode, apiKey) {
const streamRequest = new google.ima.dai.api.LiveStreamRequest();
streamRequest.assetKey = assetKey;
streamRequest.apiKey = apiKey || '';
streamRequest.networkCode = networkCode;
streamRequest.apiKey = apiKey;
streamRequest.format = 'dash';
streamManager.requestStream(streamRequest);
}
Expand All @@ -117,12 +122,14 @@ function requestLiveStream(assetKey, apiKey) {
* Requests a VOD stream with ads.
* @param {string} cmsId
* @param {string} videoId
* @param {?string} networkCode
* @param {?string} apiKey
*/
function requestVODStream(cmsId, videoId, apiKey) {
function requestVODStream(cmsId, videoId, networkCode, apiKey) {
const streamRequest = new google.ima.dai.api.VODStreamRequest();
streamRequest.contentSourceId = cmsId;
streamRequest.videoId = videoId;
streamRequest.networkCode = networkCode;
streamRequest.apiKey = apiKey;
streamRequest.format = 'dash';
streamManager.requestStream(streamRequest);
Expand Down
12 changes: 6 additions & 6 deletions hls_js/advanced/dai.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<script type="text/javascript" src="https://imasdk.googleapis.com/js/sdkloader/ima3_dai.js"></script>
<script src="https://imasdk.googleapis.com/js/sdkloader/ima3_dai.js"></script>
<script src="dai.js"></script>
<link rel="stylesheet" href="dai.css" type="text/css">
<link rel="stylesheet" href="dai.css">
</head>
<body onLoad="initPage()">
<div id="container">
Expand All @@ -22,17 +22,17 @@
<div id="live-inputs" class="input-group">
<label for="asset-key" class="input-group">Asset key: </label>
<input type="text" id="asset-key" class="input-group"/><br />
<label for="live-api-key" class="input-group">API Key (optional): </label>
<input type="text" id="live-api-key" class="input-group"/>
</div>
<div id="vod-inputs" class="input-group">
<label for="cms-id" class="input-group">CMS ID: </label>
<input type="text" id="cms-id"/>
<label for="video-id" class="input-group">Video ID: </label>
<input type="text" id="video-id" class="input-group"/><br />
<label for="vod-api-key" class="input-group">API Key (optional): </label>
<input type="text" id="vod-api-key" class="input-group"/>
</div>
<label for="network-code" class="input-group">Network code: </label>
<input type="text" id="network-code" class="input-group"/>
<label for="api-key" class="input-group">API Key (optional): </label>
<input type="text" id="api-key" class="input-group"/>
</div>

<div id="video-player">
Expand Down
24 changes: 15 additions & 9 deletions hls_js/advanced/dai.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const TEST_ASSET_KEY = 'c-rArva4ShKVIAkNfy6HUQ';
const TEST_CONTENT_SOURCE_ID = '2548831';
const TEST_VIDEO_ID = 'tears-of-steel';

const NETWORK_CODE = '21775744923';

// StreamManager which will be used to request ad-enabled streams.
let streamManager;

Expand Down Expand Up @@ -37,17 +39,17 @@ let vodInputs;
// Text box with asset key.
let assetKeyInput;

// Text box with live API key.
let liveAPIKeyInput;

// Text box with CMS ID.
let cmsIdInput;

// Text box with Video ID.
let videoIdInput;

// Text box with VOD API key.
let vodAPIKeyInput;
// Text box with network code.
let networkCodeInput;

// Text box with API key.
let apiKeyInput;

// Video element.
let videoElement;
Expand Down Expand Up @@ -101,10 +103,10 @@ function initUI() {
liveInputs = document.getElementById('live-inputs');
vodInputs = document.getElementById('vod-inputs');
assetKeyInput = document.getElementById('asset-key');
liveAPIKeyInput = document.getElementById('live-api-key');
cmsIdInput = document.getElementById('cms-id');
videoIdInput = document.getElementById('video-id');
vodAPIKeyInput = document.getElementById('vod-api-key');
networkCodeInput = document.getElementById('network-code');
apiKeyInput = document.getElementById('api-key');

liveRadio.addEventListener('click', onLiveRadioClick);

Expand All @@ -113,12 +115,14 @@ function initUI() {
liveFakeLink.addEventListener('click', () => {
onLiveRadioClick();
assetKeyInput.value = TEST_ASSET_KEY;
networkCodeInput.value = NETWORK_CODE;
});

vodFakeLink.addEventListener('click', () => {
onVODRadioClick();
cmsIdInput.value = TEST_CONTENT_SOURCE_ID;
videoIdInput.value = TEST_VIDEO_ID;
networkCodeInput.value = NETWORK_CODE;
});
}

Expand Down Expand Up @@ -238,7 +242,8 @@ function requestLiveStream() {
isLiveStream = true;
const streamRequest = new google.ima.dai.api.LiveStreamRequest();
streamRequest.assetKey = assetKeyInput.value;
streamRequest.apiKey = liveAPIKeyInput.value || '';
streamRequest.networkCode = networkCodeInput.value;
streamRequest.apiKey = apiKeyInput.value;
streamManager.requestStream(streamRequest);
}

Expand All @@ -250,7 +255,8 @@ function requestVODStream() {
const streamRequest = new google.ima.dai.api.VODStreamRequest();
streamRequest.contentSourceId = cmsIdInput.value;
streamRequest.videoId = videoIdInput.value;
streamRequest.apiKey = vodAPIKeyInput.value;
streamRequest.networkCode = networkCodeInput.value;
streamRequest.apiKey = apiKeyInput.value;
streamManager.requestStream(streamRequest);
}

Expand Down
11 changes: 8 additions & 3 deletions hls_js/dai_preroll/dai.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const TEST_AD_TAG = 'https://pubads.g.doubleclick.net/gampad/ads?' +
'cust_params=sample_ct%3Dlinear&ciu_szs=300x250%2C728x90&gdfp_req=1&' +
'output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=';

const NETWORK_CODE = '21775744923';
const API_KEY = null;

// StreamManager which will be used to request ad-enabled streams.
let streamManager;

Expand Down Expand Up @@ -139,7 +142,7 @@ function onAdsManagerLoaded(adsManagerLoadedEvent) {
adsManager.addEventListener(
google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED, function(e) {
console.log('Content resume requested.');
requestLiveStream(TEST_ASSET_KEY, null);
requestLiveStream(TEST_ASSET_KEY, NETWORK_CODE, API_KEY);
});
adsManager.addEventListener(google.ima.AdEvent.Type.PAUSED, function(e) {
console.log('Preroll paused.');
Expand Down Expand Up @@ -176,12 +179,14 @@ function requestPreroll(adTagUrl) {
/**
* Requests a Live stream with ads.
* @param {string} assetKey
* @param {?string} networkCode
* @param {?string} apiKey
*/
function requestLiveStream(assetKey, apiKey) {
function requestLiveStream(assetKey, networkCode, apiKey) {
const streamRequest = new google.ima.dai.api.LiveStreamRequest();
streamRequest.assetKey = assetKey;
streamRequest.apiKey = apiKey || '';
streamRequest.networkCode = networkCode;
streamRequest.apiKey = apiKey;
streamManager.requestStream(streamRequest);
}

Expand Down
17 changes: 12 additions & 5 deletions hls_js/simple/dai.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const BACKUP_STREAM =
const TEST_CONTENT_SOURCE_ID = '2548831';
const TEST_VIDEO_ID = 'tears-of-steel';

const NETWORK_CODE = '21775744923';
const API_KEY = null;

// StreamManager which will be used to request ad-enabled streams.
let streamManager;

Expand Down Expand Up @@ -74,9 +77,9 @@ function initPlayer() {
* Initiate stream playback.
*/
function initiatePlayback() {
requestVODStream(TEST_CONTENT_SOURCE_ID, TEST_VIDEO_ID, null);
requestVODStream(TEST_CONTENT_SOURCE_ID, TEST_VIDEO_ID, NETWORK_CODE, API_KEY);
// Uncomment line below and comment one above to request a LIVE stream.
// requestLiveStream(TEST_ASSET_KEY, null);
// requestLiveStream(TEST_ASSET_KEY, NETWORK_CODE, API_KEY);

playButton.style.display = 'none';
playButton.removeEventListener('click', initiatePlayback);
Expand All @@ -94,25 +97,29 @@ function resumePlayback() {
/**
* Requests a Live stream with ads.
* @param {string} assetKey
* @param {?string} networkCode
* @param {?string} apiKey
*/
function requestLiveStream(assetKey, apiKey) {
function requestLiveStream(assetKey, networkCode, apiKey) {
const streamRequest = new google.ima.dai.api.LiveStreamRequest();
streamRequest.assetKey = assetKey;
streamRequest.apiKey = apiKey || '';
streamRequest.networkCode = networkCode;
streamRequest.apiKey = apiKey;
streamManager.requestStream(streamRequest);
}

/**
* Requests a VOD stream with ads.
* @param {string} cmsId
* @param {string} videoId
* @param {?string} networkCode
* @param {?string} apiKey
*/
function requestVODStream(cmsId, videoId, apiKey) {
function requestVODStream(cmsId, videoId, networkCode, apiKey) {
const streamRequest = new google.ima.dai.api.VODStreamRequest();
streamRequest.contentSourceId = cmsId;
streamRequest.videoId = videoId;
streamRequest.networkCode = networkCode;
streamRequest.apiKey = apiKey;
streamManager.requestStream(streamRequest);
}
Expand Down
17 changes: 12 additions & 5 deletions native/simple/dai.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const BACKUP_STREAM =
const TEST_CONTENT_SOURCE_ID = '2548831';
const TEST_VIDEO_ID = 'tears-of-steel';

const NETWORK_CODE = '21775744923';
const API_KEY = null;

// StreamManager which will be used to request ad-enabled streams.
let streamManager;

Expand Down Expand Up @@ -43,33 +46,37 @@ function initPlayer() {
],
onStreamEvent, false);

requestVODStream(TEST_CONTENT_SOURCE_ID, TEST_VIDEO_ID, null);
requestVODStream(TEST_CONTENT_SOURCE_ID, TEST_VIDEO_ID, NETWORK_CODE, API_KEY);
// Uncomment line below and comment one above to request a LIVE stream.
// requestLiveStream(TEST_ASSET_KEY, null);
// requestLiveStream(TEST_ASSET_KEY, NETWORK_CODE, API_KEY);
}

/**
* Requests a Live stream with ads.
* @param {string} assetKey
* @param {?string} networkCode
* @param {?string} apiKey
*/
function requestLiveStream(assetKey, apiKey) {
function requestLiveStream(assetKey, networkCode, apiKey) {
const streamRequest = new google.ima.dai.api.LiveStreamRequest();
streamRequest.assetKey = assetKey;
streamRequest.apiKey = apiKey || '';
streamRequest.networkCode = networkCode;
streamRequest.apiKey = apiKey;
streamManager.requestStream(streamRequest);
}

/**
* Requests a VOD stream with ads.
* @param {string} cmsId
* @param {string} videoId
* @param {?string} networkCode
* @param {?string} apiKey
*/
function requestVODStream(cmsId, videoId, apiKey) {
function requestVODStream(cmsId, videoId, networkCode, apiKey) {
const streamRequest = new google.ima.dai.api.VODStreamRequest();
streamRequest.contentSourceId = cmsId;
streamRequest.videoId = videoId;
streamRequest.networkCode = networkCode;
streamRequest.apiKey = apiKey;
streamManager.requestStream(streamRequest);
}
Expand Down

0 comments on commit 29e1fed

Please sign in to comment.