diff options
author | Sam Potts <sam@potts.es> | 2020-03-29 12:02:59 +1100 |
---|---|---|
committer | Sam Potts <sam@potts.es> | 2020-03-29 12:02:59 +1100 |
commit | 09598f07bf062886bfa22cd8682948567e92a19a (patch) | |
tree | 2ed0de186d43b2cc27422115fe75600a12e5d303 /src/js/plugins/preview-thumbnails.js | |
parent | ef7b30c1b8a0e2d9a8cb71dfb41af0706bb8886e (diff) | |
parent | 155add66bd5b941699cea99f5c94cf8a87b030d8 (diff) | |
download | plyr-09598f07bf062886bfa22cd8682948567e92a19a.tar.lz plyr-09598f07bf062886bfa22cd8682948567e92a19a.tar.xz plyr-09598f07bf062886bfa22cd8682948567e92a19a.zip |
Merge branch 'develop' of github.com:sampotts/plyr into develop
# Conflicts:
# package.json
# yarn.lock
Diffstat (limited to 'src/js/plugins/preview-thumbnails.js')
-rw-r--r-- | src/js/plugins/preview-thumbnails.js | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/js/plugins/preview-thumbnails.js b/src/js/plugins/preview-thumbnails.js index 86eeebc8..290ce949 100644 --- a/src/js/plugins/preview-thumbnails.js +++ b/src/js/plugins/preview-thumbnails.js @@ -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); + } }); } |