Skip to content

Commit

Permalink
fix(ads): Fix IMA crash when autoplay is rejected (#4518)
Browse files Browse the repository at this point in the history
A preroll ad fails to start when there is no autoplay. This happens
because Shaka doesn't check if playback is allowed before calling the Ad
Manager's `start()` method. IMA's
https://github.com/googleads/googleads-ima-html5/tree/main/attempt_to_autoplay
addresses this by resolving a `play()` promise.

This waits to start AdManager until a `play` event from the video
element.

Closes #4179
  • Loading branch information
salles-g authored Oct 29, 2022
1 parent 29ffc89 commit d27f7d2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/ads/client_side_ad_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ goog.require('goog.asserts');
goog.require('shaka.ads.ClientSideAd');
goog.require('shaka.util.IReleasable');


/**
* A class responsible for client-side ad interactions.
* @implements {shaka.util.IReleasable}
Expand Down Expand Up @@ -218,7 +217,11 @@ shaka.ads.ClientSideAdManager = class {
// TODO (ismena): Need a better inderstanding of what this does.
// The docs say it's called to 'start playing the ads,' but I haven't
// seen the ads actually play until requestAds() is called.
this.imaAdsManager_.start();
// Note: We listen for a play event to avoid autoplay issues that might
// crash IMA.
this.video_.addEventListener('play', () => {
this.imaAdsManager_.start();
}, {once: true});
} catch (adError) {
// If there was a problem with the VAST response,
// we we won't be getting an ad. Hide ad UI if we showed it already
Expand Down

0 comments on commit d27f7d2

Please sign in to comment.