mirror of
https://github.com/iv-org/videojs-vtt-thumbnails.git
synced 2024-10-01 03:05:36 -04:00
Cache sprites on request
This commit is contained in:
parent
ceed945872
commit
5cec7f8f1e
@ -5,6 +5,9 @@ import { version as VERSION } from '../package.json'
|
|||||||
// Default options for the plugin.
|
// Default options for the plugin.
|
||||||
const defaults = {}
|
const defaults = {}
|
||||||
|
|
||||||
|
// Cache for image elements
|
||||||
|
var cache = {}
|
||||||
|
|
||||||
// Cross-compatibility for Video.js 5 and 6.
|
// Cross-compatibility for Video.js 5 and 6.
|
||||||
const registerPlugin = videojs.registerPlugin || videojs.plugin
|
const registerPlugin = videojs.registerPlugin || videojs.plugin
|
||||||
// const dom = videojs.dom || videojs;
|
// const dom = videojs.dom || videojs;
|
||||||
@ -207,6 +210,13 @@ class vttThumbnailsPlugin {
|
|||||||
for (let i = 0; i < this.vttData.length; ++i) {
|
for (let i = 0; i < this.vttData.length; ++i) {
|
||||||
let item = this.vttData[i]
|
let item = this.vttData[i]
|
||||||
if (time >= item.start && time < item.end) {
|
if (time >= item.start && time < item.end) {
|
||||||
|
// Cache miss
|
||||||
|
if (item.css.url && !cache[item.css.url]) {
|
||||||
|
let image = new Image();
|
||||||
|
image.src = item.css.url;
|
||||||
|
cache[item.css.url] = image;
|
||||||
|
}
|
||||||
|
|
||||||
return item.css
|
return item.css
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -333,6 +343,7 @@ class vttThumbnailsPlugin {
|
|||||||
cssObj.background = 'url("' + imageProps.image + '") no-repeat -' + imageProps.x + 'px -' + imageProps.y + 'px'
|
cssObj.background = 'url("' + imageProps.image + '") no-repeat -' + imageProps.x + 'px -' + imageProps.y + 'px'
|
||||||
cssObj.width = imageProps.w + 'px'
|
cssObj.width = imageProps.w + 'px'
|
||||||
cssObj.height = imageProps.h + 'px'
|
cssObj.height = imageProps.h + 'px'
|
||||||
|
cssObj.url = imageProps.image
|
||||||
|
|
||||||
return cssObj
|
return cssObj
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user