react-player
Version:
A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion
2 lines • 6.82 kB
JavaScript
(window.webpackJsonp=window.webpackJsonp||[]).push([[12],{23:function(t,e,n){"use strict";n.r(e),n.d(e,"default",(function(){return j}));var r=n(0),o=n.n(r),a=n(3),i=n(1);function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function l(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function c(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?l(Object(n),!0).forEach((function(e){P(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function s(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],r=!0,o=!1,a=void 0;try{for(var i,u=t[Symbol.iterator]();!(r=(i=u.next()).done)&&(n.push(i.value),!e||n.length!==e);r=!0);}catch(t){o=!0,a=t}finally{try{r||null==u.return||u.return()}finally{if(o)throw a}}return n}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return y(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return y(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function f(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function p(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function d(t,e){return(d=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function h(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=v(t);if(e){var o=v(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return b(this,n)}}function b(t,e){return!e||"object"!==u(e)&&"function"!=typeof e?m(t):e}function m(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function v(t){return(v=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function P(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var g=/list=([a-zA-Z0-9_-]+)/,w=/user\/([a-zA-Z0-9_-]+)\/?/,O=/youtube-nocookie\.com/,j=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&d(t,e)}(l,t);var e,n,r,u=h(l);function l(){var t;f(this,l);for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return P(m(t=u.call.apply(u,[this].concat(n))),"callPlayer",a.a),P(m(t),"parsePlaylist",(function(e){return e instanceof Array?{listType:"playlist",playlist:e.map(t.getID).join(",")}:g.test(e)?{listType:"playlist",list:s(e.match(g),2)[1]}:w.test(e)?{listType:"user_uploads",list:s(e.match(w),2)[1]}:{}})),P(m(t),"onStateChange",(function(e){var n=e.data,r=t.props,o=r.onPlay,a=r.onPause,i=r.onBuffer,u=r.onBufferEnd,l=r.onEnded,c=r.onReady,s=r.loop,y=r.config,f=y.playerVars,p=y.onUnstarted,d=window.YT.PlayerState,h=d.UNSTARTED,b=d.PLAYING,m=d.PAUSED,v=d.BUFFERING,P=d.ENDED,g=d.CUED;if(n===h&&p(),n===b&&(o(),u()),n===m&&a(),n===v&&i(),n===P){var w=!!t.callPlayer("getPlaylist");s&&!w&&(f.start?t.seekTo(f.start):t.play()),l()}n===g&&c()})),P(m(t),"mute",(function(){t.callPlayer("mute")})),P(m(t),"unmute",(function(){t.callPlayer("unMute")})),P(m(t),"ref",(function(e){t.container=e})),t}return e=l,(n=[{key:"componentDidMount",value:function(){this.props.onMount&&this.props.onMount(this)}},{key:"getID",value:function(t){return!t||t instanceof Array?null:t.match(i.l)[1]}},{key:"load",value:function(t,e){var n=this,r=this.props,o=r.playing,i=r.muted,u=r.playsinline,l=r.controls,s=r.loop,y=r.config,f=r.onError,p=y.playerVars,d=y.embedOptions,h=this.getID(t);if(e)return g.test(t)||w.test(t)||t instanceof Array?void this.player.loadPlaylist(this.parsePlaylist(t)):void this.player.cueVideoById({videoId:h,startSeconds:Object(a.f)(t)||p.start,endSeconds:Object(a.e)(t)||p.end});Object(a.b)("https://www.youtube.com/iframe_api","YT","onYouTubeIframeAPIReady",(function(t){return t.loaded})).then((function(e){n.container&&(n.player=new e.Player(n.container,c({width:"100%",height:"100%",videoId:h,playerVars:c(c({autoplay:o?1:0,mute:i?1:0,controls:l?1:0,start:Object(a.f)(t),end:Object(a.e)(t),origin:window.location.origin,playsinline:u},n.parsePlaylist(t)),p),events:{onReady:function(){s&&n.player.setLoop(!0),n.props.onReady()},onStateChange:n.onStateChange,onError:function(t){return f(t.data)}},host:O.test(t)?"https://www.youtube-nocookie.com":void 0},d)))}),f)}},{key:"play",value:function(){this.callPlayer("playVideo")}},{key:"pause",value:function(){this.callPlayer("pauseVideo")}},{key:"stop",value:function(){document.body.contains(this.callPlayer("getIframe"))&&this.callPlayer("stopVideo")}},{key:"seekTo",value:function(t){this.callPlayer("seekTo",t),this.props.playing||this.pause()}},{key:"setVolume",value:function(t){this.callPlayer("setVolume",100*t)}},{key:"setPlaybackRate",value:function(t){this.callPlayer("setPlaybackRate",t)}},{key:"setLoop",value:function(t){this.callPlayer("setLoop",t)}},{key:"getDuration",value:function(){return this.callPlayer("getDuration")}},{key:"getCurrentTime",value:function(){return this.callPlayer("getCurrentTime")}},{key:"getSecondsLoaded",value:function(){return this.callPlayer("getVideoLoadedFraction")*this.getDuration()}},{key:"render",value:function(){var t={width:"100%",height:"100%",display:this.props.display};return o.a.createElement("div",{style:t},o.a.createElement("div",{ref:this.ref}))}}])&&p(e.prototype,n),r&&p(e,r),l}(r.Component);P(j,"displayName","YouTube"),P(j,"canPlay",i.m.youtube)}}]);
//# sourceMappingURL=12.app.js.map