Hi team,
I'm trying to defer loading the HTML5 IMA SDK until a user attempts to play a video on mobile web to avoid wasting bandwidth (~250KB total; 80KB from ima3.js then 170KB from the bridge file it loads) if a user never clicks on the video. The issue I'm having is the IMA SDK is responding with a 400 error (""AdError 400: There was an error playing the video ad. Caused by: AdError 1205: The browser prevented playback initiated without user interaction.") even though I am calling "load()" on the video tag on user action and the video does play after the ad errors on mobile web.
I'm not sure if the SDK supports this, or if I'm missing something.
If it helps, I can describe the code.
I have a simple loadScript function that returns a promise that resolves when the IMA SDK has finished loading (shown below).
When a user clicks the video still div "handleClick" (also shown below) is called on that action.
Is there a better (or any) way to do this?
handleClick: function () {
video.load();
this.adDisplayContainer = new google.ima.AdDisplayContainer(adContainer, video); // adContainer and video instantiated prior to this
this.adDisplayContainer.initialize();
});
}
loadScript: function (url, id) {
return new Promise((resolve, reject) => {
let element = document.createElement('script');
element.type = 'text/javascript';
element.async = true;
element.src = url;
// Important success and error for the promise
element.onload = function () {
resolve(url);
};
element.onerror = function (e) {
reject(e);
};
document.body.appendChild(element);
});
}
Thank you,
Hunter