Merge branch 'develop' of github.com:sampotts/plyr into develop
# Conflicts: # package.json # yarn.lock
This commit is contained in:
@ -11,6 +11,7 @@ import { triggerEvent } from '../utils/events';
|
||||
import i18n from '../utils/i18n';
|
||||
import is from '../utils/is';
|
||||
import loadScript from '../utils/load-script';
|
||||
import { silencePromise } from '../utils/promise';
|
||||
import { formatTime } from '../utils/time';
|
||||
import { buildUrlParams } from '../utils/urls';
|
||||
|
||||
@ -172,6 +173,17 @@ class Ads {
|
||||
// We assume the adContainer is the video container of the plyr element that will house the ads
|
||||
this.elements.displayContainer = new google.ima.AdDisplayContainer(this.elements.container, this.player.media);
|
||||
|
||||
// Create ads loader
|
||||
this.loader = new google.ima.AdsLoader(this.elements.displayContainer);
|
||||
|
||||
// Listen and respond to ads loaded and error events
|
||||
this.loader.addEventListener(
|
||||
google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
|
||||
event => this.onAdsManagerLoaded(event),
|
||||
false,
|
||||
);
|
||||
this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error), false);
|
||||
|
||||
// Request video ads to be pre-loaded
|
||||
this.requestAds();
|
||||
}
|
||||
@ -183,17 +195,6 @@ class Ads {
|
||||
const { container } = this.player.elements;
|
||||
|
||||
try {
|
||||
// Create ads loader
|
||||
this.loader = new google.ima.AdsLoader(this.elements.displayContainer);
|
||||
|
||||
// Listen and respond to ads loaded and error events
|
||||
this.loader.addEventListener(
|
||||
google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
|
||||
event => this.onAdsManagerLoaded(event),
|
||||
false,
|
||||
);
|
||||
this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error), false);
|
||||
|
||||
// Request video ads
|
||||
const request = new google.ima.AdsRequest();
|
||||
request.adTagUrl = this.tagUrl;
|
||||
@ -369,7 +370,12 @@ class Ads {
|
||||
// TODO: So there is still this thing where a video should only be allowed to start
|
||||
// playing when the IMA SDK is ready or has failed
|
||||
|
||||
this.loadAds();
|
||||
if (this.player.ended) {
|
||||
this.loadAds();
|
||||
} else {
|
||||
// The SDK won't allow new ads to be called without receiving a contentComplete()
|
||||
this.loader.contentComplete();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@ -510,7 +516,7 @@ class Ads {
|
||||
this.playing = false;
|
||||
|
||||
// Play video
|
||||
this.player.media.play();
|
||||
silencePromise(this.player.media.play());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -563,6 +569,8 @@ class Ads {
|
||||
this.on('loaded', resolve);
|
||||
this.player.debug.log(this.manager);
|
||||
});
|
||||
// Now that the manager has been destroyed set it to also be un-initialized
|
||||
this.initialized = false;
|
||||
|
||||
// Now request some new advertisements
|
||||
this.requestAds();
|
||||
|
@ -137,19 +137,32 @@ class PreviewThumbnails {
|
||||
throw new Error('Missing previewThumbnails.src config attribute');
|
||||
}
|
||||
|
||||
// If string, convert into single-element list
|
||||
const urls = is.string(src) ? [src] : src;
|
||||
// Loop through each src URL. Download and process the VTT file, storing the resulting data in this.thumbnails
|
||||
const promises = urls.map(u => this.getThumbnail(u));
|
||||
|
||||
Promise.all(promises).then(() => {
|
||||
// Resolve promise
|
||||
const sortAndResolve = () => {
|
||||
// Sort smallest to biggest (e.g., [120p, 480p, 1080p])
|
||||
this.thumbnails.sort((x, y) => x.height - y.height);
|
||||
|
||||
this.player.debug.log('Preview thumbnails', this.thumbnails);
|
||||
|
||||
resolve();
|
||||
});
|
||||
};
|
||||
|
||||
// Via callback()
|
||||
if (is.function(src)) {
|
||||
src(thumbnails => {
|
||||
this.thumbnails = thumbnails;
|
||||
sortAndResolve();
|
||||
});
|
||||
}
|
||||
// VTT urls
|
||||
else {
|
||||
// If string, convert into single-element list
|
||||
const urls = is.string(src) ? [src] : src;
|
||||
// Loop through each src URL. Download and process the VTT file, storing the resulting data in this.thumbnails
|
||||
const promises = urls.map(u => this.getThumbnail(u));
|
||||
// Resolve
|
||||
Promise.all(promises).then(sortAndResolve);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -204,6 +204,9 @@ const vimeo = {
|
||||
player.embed.setPlaybackRate(input).then(() => {
|
||||
speed = input;
|
||||
triggerEvent.call(player, player.media, 'ratechange');
|
||||
}).catch(() => {
|
||||
// Cannot set Playback Rate, Video is probably not on Pro account
|
||||
player.options.speed = [1];
|
||||
});
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user