-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshot.min.js
1 lines (1 loc) · 2.25 KB
/
snapshot.min.js
1
!function t(e,n,o){function i(a,r){if(!n[a]){if(!e[a]){var p="function"==typeof require&&require;if(!r&&p)return p(a,!0);if(s)return s(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var u=n[a]={exports:{}};e[a][0].call(u.exports,function(t){var n=e[a][1][t];return i(n||t)},u,u.exports,t,e,n,o)}return n[a].exports}for(var s="function"==typeof require&&require,a=0;a<o.length;a++)i(o[a]);return i}({1:[function(t,e,n){"use strict";mejs.i18n.en["mejs.snapshot"]="Take a Snapshot",Object.assign(mejs.MepDefaults,{snapError:null,snapSuccess:null,snapType:"png",snapQuality:.2,snapShot:!0,snapWidth:null,snapHeight:null}),Object.assign(MediaElementPlayer.prototype,{buildsnapshot:function(t,e,n,o){var i=this;if(!1===i.options.isVideo)return;var s,a,r,p=i.options.snapShot,l=mejs.i18n.t("mejs.snapshot"),u=o.firstChild,d=document.querySelector("canvas"),c=d.getContext("2d"),h=document.createElement("div");h.className=i.options.classPrefix+"button "+i.options.classPrefix+"snapshot-button",h.innerHTML='<button type="button" aria-controls="'+i.id+'" title="'+l+'" aria-label="'+l+'" tabindex="0"></button>',i.addControlElement(h,"snapshot"),o.addEventListener("loadedmetadata",()=>{r=u.videoWidth/u.videoHeight,s=null!=i.options.snapWidth?parseInt(i.options.snapWidth):u.videoWidth-100,a=null!=i.options.snapHeight?parseInt(i.options.snapHeight):parseInt(s/r,10),d.width=s,d.height=a},!1);let f=!1,m=i.options.snapSuccess,v=i.options.snapError,b=i.options.snapType,g=i.options.snapQuality;o.addEventListener("seeking",()=>{f=!0}),o.addEventListener("seeked",()=>{f=!1}),h.addEventListener("click",()=>{if(!1===f&&o.currentTime>0){if(y(m)&&m.call(this,L(b,g)),!0===p)return E(b,g)}else if(y(v))return v.call(this)});var y=t=>t&&"[object Function]"==={}.toString.call(t),E=()=>{d.toBlob(function(t){var e=URL.createObjectURL(t),n=document.createElement("a");document.body.appendChild(n),n.setAttribute("href",e),n.className="snapshot-download",n.setAttribute("download","snapshot-"+Math.floor(o.currentTime)+"."+i.options.snapType),n.click(),URL.revokeObjectURL(e)},"image/"+i.options.snapType,i.options.snapQuality)},L=(t,e)=>{return c.fillRect(0,0,s,a),c.drawImage(u,0,0,s,a),{url:d.toDataURL("image/"+t,e),type:"image/"+t,quality:e,width:s,height:a}}}})},{}]},{},[1]);