Skip to content

Commit

Permalink
fix(Ads): Don't try to play Image and HTML overlay interstitials (sha…
Browse files Browse the repository at this point in the history
…ka-project#7697)

We don't currently support those types of interstitials, so this PR makes the player properly reject them.
  • Loading branch information
avelad authored Nov 30, 2024
1 parent 743b451 commit 87cbf4d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
52 changes: 48 additions & 4 deletions lib/ads/interstitial_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ goog.require('shaka.ads.Utils');
goog.require('shaka.log');
goog.require('shaka.media.PreloadManager');
goog.require('shaka.net.NetworkingEngine');
goog.require('shaka.net.NetworkingUtils');
goog.require('shaka.util.Dom');
goog.require('shaka.util.Error');
goog.require('shaka.util.EventManager');
Expand Down Expand Up @@ -543,13 +544,56 @@ shaka.ads.InterstitialAdManager = class {
*/
async setupAd_(interstitial, sequenceLength, adPosition, initialTime,
oncePlayed = 0) {
this.determineIfUsingBaseVideo_();
goog.asserts.assert(this.video_, 'Must have video');
shaka.log.info('Starting interstitial',
interstitial.startTime, 'at', this.lastTime_);

this.lastPlayedAd_ = interstitial;

shaka.log.info('Starting interstitial',
interstitial.startTime, 'at', this.lastTime_);
let interstitialMimeType = interstitial.mimeType;
if (!interstitialMimeType) {
try {
const netEngine = this.player_.getNetworkingEngine();
goog.asserts.assert(netEngine, 'Need networking engine');
// eslint-disable-next-line require-atomic-updates
interstitialMimeType = await shaka.net.NetworkingUtils.getMimeType(
interstitial.uri, netEngine,
this.basePlayer_.getConfiguration().streaming.retryParameters);
} catch (error) {}
}
if (interstitialMimeType) {
if (interstitialMimeType.startsWith('image/')) {
shaka.log.alwaysWarn('Unsupported image interstitial', interstitial);
if (!interstitial.overlay) {
return;
}
// TODO implement support for image in overlay
return;
} else if (interstitialMimeType === 'text/html') {
shaka.log.alwaysWarn('Unsupported HTML interstitial', interstitial);
if (!interstitial.overlay) {
return;
}
// TODO implement support for HTML in overlay
return;
}
}
this.setupVideoAd_(interstitial, sequenceLength, adPosition, initialTime,
oncePlayed);
}


/**
* @param {shaka.extern.AdInterstitial} interstitial
* @param {number} sequenceLength
* @param {number} adPosition
* @param {number} initialTime the clock time the ad started at
* @param {number} oncePlayed
* @private
*/
async setupVideoAd_(interstitial, sequenceLength, adPosition, initialTime,
oncePlayed) {
this.determineIfUsingBaseVideo_();
goog.asserts.assert(this.video_, 'Must have video');

const startTime = Date.now();

Expand Down
3 changes: 3 additions & 0 deletions lib/net/networking_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ shaka.net.NetworkingUtils.EXTENSIONS_TO_MIME_TYPES_ = {
'lrc': 'application/x-subtitle-lrc',
'ssa': 'text/x-ssa',
'ass': 'text/x-ssa',
'jpeg': 'image/jpeg',
'jpg': 'image/jpeg',
'png': 'image/png',
'svg': 'image/svg+xml',
'webp': 'image/webp',
'avif': 'image/avif',
'html': 'text/html',
'htm': 'text/html',
};

0 comments on commit 87cbf4d

Please sign in to comment.