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