/*! * artplayer-tool-thumbnail.js v1.0.5 * Github: https://github.com/zhw2590582/ArtPlayer#readme * (c) 2017-2018 Harvey Zack * Released under the MIT License. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t["artplayer-tool-thumbnail"]={})}(this,function(t){"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(u,10,1e3),this.option.height=d(a,10,1e3),this.option.column=d(s,1,1e3),this}},{key:"inputChange",value:function(){var e=this,t=this.option.delay,n=["video/mp4","audio/ogg","video/webm"],o=this.option.fileInput.files[0];if(o){this.errorHandle(n.includes(o.type),"Only file types are supported: ".concat(n.toString(),", but got ").concat(o.type));var i=URL.createObjectURL(o);this.videoUrl=i,this.file=o,this.emit("file",this.file),this.video.src=i,p(t).then(function(){e.emit("video",e.video)}).catch(function(t){e.emit("error",t.message),console.error(t)})}}},{key:"start",value:function(){var n=this,t=this.option,o=t.width,i=t.height,r=t.number,u=t.delay;this.density=r/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(),a=this.creatCanvas(),s=a.getContext("2d");this.emit("canvas",a);var c,l=e.map(function(t,e){return function(){return n.video.currentTime=t.time,p(u).then(function(){s.drawImage(n.video,t.x,t.y,o,i),a.toBlob(function(t){n.thumbnailUrl&&URL.revokeObjectURL(n.thumbnailUrl),n.thumbnailUrl=URL.createObjectURL(t),n.emit("update",n.thumbnailUrl,(e+1)/r)})}).catch(function(t){console.error(t)})}});return this.processing=!0,(c=l,c.reduce(function(t,e){return t.then(e)},Promise.resolve())).then(function(){return p(2*u).then(function(){n.processing=!1,n.emit("done")}).catch(function(t){n.processing=!1,n.emit("error",t.message),console.error(t)})}).catch(function(t){n.processing=!1,n.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,u=[r];u.length