Skip to content

Commit

Permalink
feat(Ads): Add support for interstitials when using src= (#6777)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Jun 10, 2024
1 parent 205d58b commit 59304b8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ shaka.ads.InterstitialAdManager = class {
* @param {shaka.extern.Interstitial} interstitial
*/
async addMetadata(interstitial) {
if (this.basePlayer_.getLoadMode() == shaka.Player.LoadMode.SRC_EQUALS &&
this.usingBaseVideo_) {
shaka.log.alwaysWarn(
'Unsupported interstitial when using single media element',
interstitial);
return;
}
this.updatePlayerConfig_();
const interstitialsAd = await this.getInterstitialsInfo_(interstitial);
if (interstitialsAd.length) {
Expand Down
30 changes: 30 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -3006,13 +3006,43 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
return;
}

/** @type {!Array.<shaka.extern.Interstitial>} */
const interstitials = [];

for (const cue of track.activeCues) {
this.dispatchMetadataEvent_(cue.startTime, cue.endTime,
cue.type, cue.value);

if (this.adManager_) {
this.adManager_.onCueMetadataChange(cue.value);
}
if (cue.type == 'com.apple.quicktime.HLS' && cue.startTime != null) {
let interstitial = interstitials.find((i) => {
return i.startTime == cue.startTime && i.endTime == cue.endTime;
});
if (!interstitial) {
interstitial = /** @type {shaka.extern.Interstitial} */ ({
startTime: cue.startTime,
endTime: cue.endTime,
values: [],
});
interstitials.push(interstitial);
}
interstitial.values.push(cue.value);
}
}
for (const interstitial of interstitials) {
const isValidInterstitial = interstitial.values.some((value) => {
return value.key == 'X-ASSET-URI' || value.key == 'X-ASSET-LIST';
});
if (!isValidInterstitial) {
continue;
}
if (this.adManager_) {
goog.asserts.assert(this.video_, 'Must have video');
this.adManager_.onInterstitialMetadata(
this, this.video_, interstitial);
}
}
});

Expand Down

0 comments on commit 59304b8

Please sign in to comment.