Plugin tweaks for ads and previews

This commit is contained in:
Sam Potts
2019-01-26 16:31:47 +11:00
parent c577eb01ce
commit c44351507f
20 changed files with 149 additions and 60 deletions

39
dist/plyr.js vendored
View File

@ -3466,7 +3466,8 @@ typeof navigator === "object" && (function (global, factory) {
// Register for an account here: http://vi.ai/publisher-video-monetization/?aid=plyrio
ads: {
enabled: false,
publisherId: ''
publisherId: '',
tagUrl: ''
},
// YouTube nocookies mode
noCookie: false,
@ -5970,7 +5971,7 @@ typeof navigator === "object" && (function (global, factory) {
_classCallCheck(this, Ads);
this.player = player;
this.publisherId = player.config.ads.publisherId;
this.config = player.config.ads;
this.playing = false;
this.initialized = false;
this.elements = {
@ -6037,7 +6038,7 @@ typeof navigator === "object" && (function (global, factory) {
this.listeners(); // Setup the IMA SDK
this.setupIMA();
} // Build the default tag URL
} // Build the tag URL
}, {
key: "setupIMA",
@ -6206,7 +6207,8 @@ typeof navigator === "object" && (function (global, factory) {
var container = this.player.elements.container; // Retrieve the ad from the event. Some events (e.g. ALL_ADS_COMPLETED)
// don't have ad object associated
var ad = event.getAd(); // Proxy event
var ad = event.getAd();
var adData = event.getAdData(); // Proxy event
var dispatchEvent = function dispatchEvent(type) {
var event = "ads".concat(type.replace(/_/g, '').toLowerCase());
@ -6288,6 +6290,13 @@ typeof navigator === "object" && (function (global, factory) {
dispatchEvent(event.type);
break;
case google.ima.AdEvent.Type.LOG:
if (adData.adError) {
this.player.debug.warn("Non-fatal ad error: ".concat(adData.adError.getMessage()));
}
break;
default:
break;
}
@ -6320,9 +6329,8 @@ typeof navigator === "object" && (function (global, factory) {
this.player.on('ended', function () {
_this8.loader.contentComplete();
});
this.player.on('seeking', function () {
this.player.on('timeupdate', function () {
time = _this8.player.currentTime;
return time;
});
this.player.on('seeked', function () {
var seekedTime = _this8.player.currentTime;
@ -6540,11 +6548,18 @@ typeof navigator === "object" && (function (global, factory) {
}, {
key: "enabled",
get: function get() {
return this.player.isHTML5 && this.player.isVideo && this.player.config.ads.enabled && !is.empty(this.publisherId);
var config = this.config;
return this.player.isHTML5 && this.player.isVideo && config.enabled && (!is.empty(config.publisherId) || is.url(config.tagUrl));
}
}, {
key: "tagUrl",
get: function get() {
var config = this.config;
if (is.url(config.tagUrl)) {
return config.tagUrl;
}
var params = {
AV_PUBLISHERID: '58c25bb0073ef448b1087ad6',
AV_CHANNELID: '5a0458dc28a06145e4519d21',
@ -6860,12 +6875,20 @@ typeof navigator === "object" && (function (global, factory) {
this.toggleThumbContainer(true);
this.setThumbContainerSizeAndPos();
} // Find the desired thumbnail index
// TODO: Handle a video longer than the thumbs where thumbNum is null
var thumbNum = this.thumbnails[0].frames.findIndex(function (frame) {
return _this5.seekTime >= frame.startTime && _this5.seekTime <= frame.endTime;
});
var qualityIndex = 0; // Check to see if we've already downloaded higher quality versions of this image
var hasThumb = thumbNum >= 0;
var qualityIndex = 0;
this.toggleThumbContainer(hasThumb); // No matching thumb found
if (!hasThumb) {
return;
} // Check to see if we've already downloaded higher quality versions of this image
this.thumbnails.forEach(function (thumbnail, index) {
if (_this5.loadedImages.includes(thumbnail.frames[thumbNum].text)) {