Merge pull request #1705 from doublex/master
preview-thumbnails via src:callback()
This commit is contained in:
commit
48758bd5f0
@ -137,19 +137,34 @@ class PreviewThumbnails {
|
|||||||
throw new Error('Missing previewThumbnails.src config attribute');
|
throw new Error('Missing previewThumbnails.src config attribute');
|
||||||
}
|
}
|
||||||
|
|
||||||
// If string, convert into single-element list
|
// Resolve promise
|
||||||
const urls = is.string(src) ? [src] : src;
|
const sortAndResolve = () => {
|
||||||
// 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(() => {
|
|
||||||
// Sort smallest to biggest (e.g., [120p, 480p, 1080p])
|
// Sort smallest to biggest (e.g., [120p, 480p, 1080p])
|
||||||
this.thumbnails.sort((x, y) => x.height - y.height);
|
this.thumbnails.sort((x, y) => x.height - y.height);
|
||||||
|
|
||||||
this.player.debug.log('Preview thumbnails', this.thumbnails);
|
this.player.debug.log('Preview thumbnails', this.thumbnails);
|
||||||
|
|
||||||
resolve();
|
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);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user