diff --git a/lib/ads/ad_utils.js b/lib/ads/ad_utils.js index aec244e8f3..aecd6e8cd9 100644 --- a/lib/ads/ad_utils.js +++ b/lib/ads/ad_utils.js @@ -130,17 +130,29 @@ shaka.ads.Utils = class { */ static processNonLinearAd_(interstitials, currentTime, nonLinear) { const TXml = shaka.util.TXml; - const staticResource = TXml.findChild(nonLinear, 'StaticResource'); - if (!staticResource) { - return; + let mimeType = null; + let resource = TXml.findChild(nonLinear, 'StaticResource'); + if (resource) { + mimeType = resource.attributes['creativeType']; + } else { + resource = TXml.findChild(nonLinear, 'HTMLResource'); + if (!resource) { + return; + } + mimeType = 'text/html'; } - const adUrl = TXml.getContents(staticResource); + let adUrl = TXml.getContents(resource); if (!adUrl) { return; } - const width = TXml.parseAttr(nonLinear, 'width', TXml.parseInt); - const height = TXml.parseAttr(nonLinear, 'height', TXml.parseInt); - if (!width || !height) { + if (mimeType === 'text/html') { + adUrl = 'data:text/html;charset=UTF-8,' + encodeURIComponent(adUrl); + } + const width = TXml.parseAttr(nonLinear, 'width', TXml.parseInt) || + TXml.parseAttr(nonLinear, 'expandedWidth', TXml.parseInt); + const height = TXml.parseAttr(nonLinear, 'height', TXml.parseInt) || + TXml.parseAttr(nonLinear, 'expandedHeight', TXml.parseInt); + if (!width && !height) { return; } let playoutLimit = null; @@ -158,7 +170,7 @@ shaka.ads.Utils = class { startTime: startTime, endTime: null, uri: adUrl, - mimeType: staticResource.attributes['creativeType'] || null, + mimeType, isSkippable: false, skipOffset: null, skipFor: null, @@ -180,8 +192,8 @@ shaka.ads.Utils = class { y: 0, }, size: { - x: width, - y: height, + x: width || 0, + y: height || 0, }, }, });