diff options
author | Sam Potts <sam@potts.es> | 2020-03-29 11:19:38 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-29 11:19:38 +1100 |
commit | 48758bd5f052a7816846caa698981642d92a763a (patch) | |
tree | 6303fefbbb42b6d063973942ca5ab49a33aa8c58 /src/js | |
parent | 2f26c80c8884911db7029b8f9fcf4e8e0c5e57d6 (diff) | |
parent | ace682abbdeba13ea3664e9dde38a903a4a5da5e (diff) | |
download | plyr-48758bd5f052a7816846caa698981642d92a763a.tar.lz plyr-48758bd5f052a7816846caa698981642d92a763a.tar.xz plyr-48758bd5f052a7816846caa698981642d92a763a.zip |
Merge pull request #1705 from doublex/master
preview-thumbnails via src:callback()
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/plugins/preview-thumbnails.js | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/js/plugins/preview-thumbnails.js b/src/js/plugins/preview-thumbnails.js index 86eeebc8..4c13ab33 100644 --- a/src/js/plugins/preview-thumbnails.js +++ b/src/js/plugins/preview-thumbnails.js @@ -137,19 +137,34 @@ 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)) { + // Ask + let that = this; + src(function(thumbnails) { + that.thumbnails = thumbnails; + // Resolve + 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); + } }); } |