/*! * artplayer-tool-thumbnail.js v3.1.4 * Github: https://github.com/zhw2590582/ArtPlayer#readme * (c) 2017-2019 Harvey Zack * Released under the MIT License. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self)["artplayer-tool-thumbnail"]=e()}(this,function(){"use strict";var o=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")};function i(t,e){for(var n=0;n"),["delay","number","width","height","column"].forEach(function(t){e.errorHandle("number"==typeof e.option[t],"The '".concat(t,"' is not a number"))}),this.option.delay=d(i,10,1e3),this.option.number=d(r,10,1e3),this.option.width=d(a,10,1e3),this.option.height=d(u,10,1e3),this.option.column=d(s,1,1e3),this}},{key:"inputChange",value:function(){var t=this.option.fileInput.files[0];this.loadVideo(t)}},{key:"loadVideo",value:function(t){var e=this,n=this.option.delay;if(t){var o=this.video.canPlayType(t.type);this.errorHandle("maybe"===o||"probably"===o,"Playback of this file format is not supported: ".concat(t.type));var i=URL.createObjectURL(t);this.videoUrl=i,this.file=t,this.emit("file",this.file),this.video.src=i,p(n).then(function(){e.emit("video",e.video)}).catch(function(t){e.emit("error",t.message),console.error(t)})}}},{key:"start",value:function(){var o=this,t=this.option,i=t.width,r=t.height,a=t.number,u=t.delay;this.density=a/this.video.duration,this.errorHandle(this.file&&this.video,"Please select the video file first"),this.errorHandle(!this.processing,"There is currently a task in progress, please wait a moment..."),this.errorHandle(this.density<=1,"The preview density cannot be greater than 1, but got ".concat(this.density));var e=this.creatScreenshotDate(),s=this.creatCanvas(),c=s.getContext("2d");this.emit("canvas",s);var n=e.map(function(t,n){return function(){return o.video.currentTime=t.time,new Promise(function(e){p(u).then(function(){c.drawImage(o.video,t.x,t.y,i,r),s.toBlob(function(t){o.thumbnailUrl&&URL.revokeObjectURL(o.thumbnailUrl),o.thumbnailUrl=URL.createObjectURL(t),o.emit("update",o.thumbnailUrl,(n+1)/a),e()})}).catch(function(t){console.error(t)})})}});return this.processing=!0,function(t){return t.reduce(function(t,e){return t.then(e)},Promise.resolve())}(n).then(function(){return p(2*u).then(function(){o.processing=!1,o.emit("done")}).catch(function(t){o.processing=!1,o.emit("error",t.message),console.error(t)})}).catch(function(t){o.processing=!1,o.emit("error",t.message),console.error(t)})}},{key:"creatScreenshotDate",value:function(){for(var t=this.option,e=t.number,n=t.width,o=t.height,i=t.column,r=this.video.duration/e,a=[r];a.length