UNPKG

@flowplayer/player

Version:
2 lines (1 loc) 6 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).flowplayer=e.flowplayer||{},e.flowplayer.fas=t())}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var t=function(e){var t={exports:{}};return e(t,t.exports),t.exports}((function(t,r){var o,s;o=e,(s=function(e,t,r){if(!(this instanceof s))return new s(e,t,r);if(void 0===t)this.frameRate=29.97;else{if(!("number"==typeof t&&t>0))throw new Error("Number expected as framerate");this.frameRate=t}if(23.976!==this.frameRate&&24!==this.frameRate&&25!==this.frameRate&&29.97!==this.frameRate&&30!==this.frameRate&&50!==this.frameRate&&59.94!==this.frameRate&&60!==this.frameRate)throw new Error("Unsupported framerate");if(this.dropFrame="boolean"==typeof r?r:29.97===this.frameRate||59.94===this.frameRate,"number"==typeof e)this.frameCount=Math.round(e),this._frameCountToTimeCode();else if("string"==typeof e){var o=e.match("^([012]\\d):(\\d\\d):(\\d\\d)(:|;|\\.)(\\d\\d)$");if(!o)throw new Error("Timecode string expected as HH:MM:SS:FF or HH:MM:SS;FF");this.hours=parseInt(o[1]),this.minutes=parseInt(o[2]),this.seconds=parseInt(o[3]),"boolean"!=typeof r&&(this.dropFrame=":"!==o[4]),this.frames=parseInt(o[5]),this._timeCodeToFrameCount()}else if("object"==typeof e&&e instanceof Date){var i=new Date(e.getFullYear(),e.getMonth(),e.getDate(),0,0,0),a=60*i.getTimezoneOffset()*1e3,n=60*e.getTimezoneOffset()*1e3;this.frameCount=Math.round((e-i+(a-n))*this.frameRate/1e3),this._frameCountToTimeCode()}else if("object"==typeof e&&e.hours>=0)this.hours=e.hours,this.minutes=e.minutes,this.seconds=e.seconds,this.frames=e.frames,this._timeCodeToFrameCount();else{if(void 0!==e)throw new Error("Timecode() constructor expects a number, timecode string, or Date()");this.frameCount=0}return this._validate(e),this}).prototype._validate=function(e){if(this.dropFrame&&29.97!==this.frameRate&&59.94!==this.frameRate)throw new Error("Drop frame is only supported for 29.97 and 59.94 fps");if(this.hours>23||this.minutes>59||this.seconds>59||this.frames>=this.frameRate||this.dropFrame&&0===this.seconds&&this.minutes%10&&this.frames<this.frameRate/29.97*2)throw new Error("Invalid timecode"+JSON.stringify(e))},s.prototype._frameCountToTimeCode=function(){var e=this.frameCount;if(this.dropFrame){var t=29.97===this.frameRate?2:4,r=Math.floor(this.frameCount/(17982*t/2)),o=this.frameCount%(17982*t/2);o<t&&(o+=t),e+=9*t*r+t*Math.floor((o-t)/(1798*t/2))}var s=Math.round(this.frameRate);this.frames=e%s,this.seconds=Math.floor(e/s)%60,this.minutes=Math.floor(e/(60*s))%60,this.hours=Math.floor(e/(3600*s))%24},s.prototype._timeCodeToFrameCount=function(){if(this.frameCount=(3600*this.hours+60*this.minutes+this.seconds)*Math.round(this.frameRate)+this.frames,this.dropFrame){var e=60*this.hours+this.minutes,t=29.97===this.frameRate?2:4;this.frameCount-=t*(e-Math.floor(e/10))}},s.prototype.toString=function(e){var t=this.frames,r="";if("string"==typeof e){if("field"!==e)throw new Error("Unsupported string format");this.frameRate<=30?r=".0":(t=Math.floor(t/2),r=".".concat((this.frameCount%2).toString()))}return"".concat(this.hours<10?"0":"",this.hours.toString(),":",this.minutes<10?"0":"",this.minutes.toString(),":",this.seconds<10?"0":"",this.seconds.toString(),this.dropFrame?";":":",t<10?"0":"",t.toString(),r)},s.prototype.valueOf=function(){return this.frameCount},s.prototype.add=function(e,t,r){if("number"!=typeof e)return e instanceof s||(e=new s(e,this.frameRate,this.dropFrame)),this.add(e.frameCount,t,r);var o=this.frameCount+Math.round(e)*(t?-1:1);if(o<0&&r>0&&(o=Math.round(86400*this.frameRate)+o)/this.frameRate/3600>r)throw new Error("Rollover arithmetic exceeds max permitted");if(o<0)throw new Error("Negative timecodes not supported");return this.frameCount=o,this.frameCount=this.frameCount%Math.round(86400*this.frameRate),this._frameCountToTimeCode(),this},s.prototype.subtract=function(e,t){return this.add(e,!0,t)},s.prototype.toDate=function(){var e=this.frameCount/this.frameRate*1e3,t=new Date;t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0);var r=new Date(t.valueOf()+e),o=60*t.getTimezoneOffset()*1e3,s=60*r.getTimezoneOffset()*1e3;return new Date(t.valueOf()+e+(s-o))},"string"!=typeof r.nodeName?t.exports=s:o&&(o.Timecode=s)}));function r(e,r,o){o=o||0;const s=new Date;s.setHours(0),s.setMinutes(0),s.setSeconds(0),e=Math.max(parseFloat(e.toFixed(3))+.001+1*o/r,0),s.setMilliseconds(1e3*e);return new t(s,r).toString()}var o;const s=30,i=0,a=((o=class FAS{constructor(e,t){this.player=t,this.frame_rate=s,this.frame_offset=i}init(e,t,r){0!=r.reaper&&(r.on("loadstart",(function(){r.hls&&r.setOpts({fas:{frame_offset:-1}})})),r.on("config",e=>{var t,r,o,s;this.frame_rate=(null===(r=null===(t=e.data)||void 0===t?void 0:t.fas)||void 0===r?void 0:r.frame_rate)||this.frame_rate,this.frame_offset=(null===(s=null===(o=e.data)||void 0===o?void 0:o.fas)||void 0===s?void 0:s.frame_offset)||this.frame_offset}),r.fas=this)}current_frame(){return e=r(this.player.currentTime,this.frame_rate,this.frame_offset),o=this.frame_rate,new t(e,o).frameCount;var e,o}seek_to(e){this.player.currentTime=function(e,r,o){o=o||0;const s=1*(new t(e,r).frameCount+o)/r;return Number((s+.001).toFixed(5))}(e,this.frame_rate,-this.frame_offset)}current_timecode(){return r(this.player.currentTime,this.frame_rate,this.frame_offset)}jump(e){this.seek_to(this.current_frame()+e)}}).pluginName="fas",o);return function(e,t){if("object"==typeof exports&&"undefined"!=typeof module)return t;if(null===document.currentScript)return t;"flowplayer"in e||(e.flowplayer={extensions:[]});const r=e.flowplayer;return"function"==typeof r?(r(t),t):(Array.isArray(r.extensions)||(r.extensions=[]),~r.extensions.indexOf(t)||r.extensions.push(t),t)}(window,a)}));