Skip to content

Commit

Permalink
feat(Ads): Skip play detection in some devices (#6443)
Browse files Browse the repository at this point in the history
This configuration solves problems with some devices not being able to
play a pre-roll.
  • Loading branch information
avelad authored Apr 16, 2024
1 parent 2d42933 commit 91f74e7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 3 additions & 1 deletion demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ shakaDemo.Config = class {
const docLink = this.resolveExternLink_('.AdsConfiguration');
this.addSection_('Ads', docLink)
.addBoolInput_('Custom playhead tracker',
'ads.customPlayheadTracker');
'ads.customPlayheadTracker')
.addBoolInput_('Skip play detection',
'ads.skipPlayDetection');
}

/**
Expand Down
9 changes: 8 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,8 @@ shaka.extern.MediaSourceConfiguration;

/**
* @typedef {{
* customPlayheadTracker: boolean
* customPlayheadTracker: boolean,
* skipPlayDetection: boolean
* }}
*
* @description
Expand All @@ -1456,6 +1457,12 @@ shaka.extern.MediaSourceConfiguration;
* Client Side. This is useful because it allows you to implement the use of
* IMA on platforms that do not support multiple video elements.
* This value defaults to <code>false</code>.
* @property {boolean} skipPlayDetection
* If this is true, we will load Client Side ads without waiting for a play
* event.
* Defaults to <code>false</code> except on Tizen, WebOS, Chromecast,
* Hisense, PlayStation 4, PlayStation5, Xbox whose default value is
* <code>true</code>.
*
* @exportDoc
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/ads/client_side_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ shaka.ads.ClientSideAdManager = class {
// seen the ads actually play until requestAds() is called.
// Note: We listen for a play event to avoid autoplay issues that might
// crash IMA.
if (this.videoPlayed_) {
if (this.videoPlayed_ || this.config_.skipPlayDetection) {
this.imaAdsManager_.start();
} else {
this.eventManager_.listenOnce(this.video_, 'play', () => {
Expand Down
12 changes: 12 additions & 0 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,20 @@ shaka.util.PlayerConfiguration = class {
},
};

let skipPlayDetection = false;
if (shaka.util.Platform.isWebOS() ||
shaka.util.Platform.isTizen() ||
shaka.util.Platform.isChromecast() ||
shaka.util.Platform.isHisense() ||
shaka.util.Platform.isPS5() ||
shaka.util.Platform.isPS4() ||
shaka.util.Platform.isXboxOne()) {
skipPlayDetection = true;
}

const ads = {
customPlayheadTracker: false,
skipPlayDetection,
};

const AutoShowText = shaka.config.AutoShowText;
Expand Down

0 comments on commit 91f74e7

Please sign in to comment.