UNPKG

videojs-playlist

Version:
7 lines 3.83 kB
/** * videojs-playlist * @version 4.0.0 * @copyright 2017 Brightcove, Inc. * @license Apache-2.0 */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("video.js")):"function"==typeof define&&define.amd?define(["video.js"],t):e.videojsPlaylist=t(e.videojs)}(this,function(e){"use strict";e="default"in e?e["default"]:e;var t,n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r=t="undefined"!=typeof window?window:void 0!==n?n:"undefined"!=typeof self?self:{},i=function(e){return"number"==typeof e&&!isNaN(e)&&e>=0&&e<Infinity},o=function(e){e.playlist.autoadvance_.timeout&&r.clearTimeout(e.playlist.autoadvance_.timeout),e.playlist.autoadvance_.trigger&&e.off("ended",e.playlist.autoadvance_.trigger),e.playlist.autoadvance_.timeout=null,e.playlist.autoadvance_.trigger=null},u=function(e,t){o(e),i(t)&&(e.playlist.autoadvance_.trigger=function(){e.playlist.autoadvance_.timeout=r.setTimeout(function(){o(e),e.playlist.next()},1e3*t)},e.one("ended",e.playlist.autoadvance_.trigger))},a=function(e){for(var t=e.remoteTextTracks(),n=t&&t.length||0;n--;)e.removeRemoteTextTrack(t[n])},c=function(e,t,n){var r=!e.paused()||e.ended();return e.trigger("beforeplaylistitem",n),e.poster(n.poster||""),e.src(n.sources),a(e),(n.textTracks||[]).forEach(e.addRemoteTextTrack.bind(e)),e.trigger("playlistitem",n),r&&e.play(),u(e,t),e},f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},l=function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},d=function(e,t){var n=e,r=t;return"object"===(void 0===e?"undefined":f(e))&&(n=e.src),"object"===(void 0===t?"undefined":f(t))&&(r=t.src),/^\/\//.test(n)&&(r=r.slice(r.indexOf("//"))),/^\/\//.test(r)&&(n=n.slice(n.indexOf("//"))),n===r},s=function(e,t){for(var n=0;n<e.length;n++){var r=e[n].sources;if(Array.isArray(r))for(var i=0;i<r.length;i++){var o=r[i];if(o&&d(o,t))return n}}return-1},y=function(t,n){var i=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0,a=Array.isArray(n)?n.slice():[],f=t.playlist=function(e){var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;return Array.isArray(e)&&(a=e.slice(),-1!==n&&f.currentItem(n),f.changeTimeout_=r.setTimeout(function(){t.trigger("playlistchange")},0)),a.slice()};return t.on("loadstart",function(){-1===f.currentItem()&&o(t)}),t.on("dispose",function(){r.clearTimeout(f.changeTimeout_)}),l(f,{currentIndex_:-1,player_:t,autoadvance_:{},repeat_:!1,currentItem:function(e){return"number"==typeof e&&f.currentIndex_!==e&&e>=0&&e<a.length?(f.currentIndex_=e,c(f.player_,f.autoadvance_.delay,a[f.currentIndex_])):f.currentIndex_=f.indexOf(f.player_.currentSrc()||""),f.currentIndex_},contains:function(e){return-1!==f.indexOf(e)},indexOf:function(e){if("string"==typeof e)return s(a,e);for(var t=Array.isArray(e)?e:e.sources,n=0;n<t.length;n++){var r=t[n];if("string"==typeof r)return s(a,r);if(r.src)return s(a,r.src)}return-1},first:function(){if(a.length)return a[f.currentItem(0)];f.currentIndex_=-1},last:function(){if(a.length)return a[f.currentItem(a.length-1)];f.currentIndex_=-1},next:function(){var e=void 0;if(f.repeat_?(e=f.currentIndex_+1)>a.length-1&&(e=0):e=Math.min(f.currentIndex_+1,a.length-1),e!==f.currentIndex_)return a[f.currentItem(e)]},previous:function(){var e=Math.max(f.currentIndex_-1,0);if(e!==f.currentIndex_)return a[f.currentItem(e)]},autoadvance:function(e){f.autoadvance_.delay=e,u(f.player_,e)},repeat:function(t){return t!==undefined&&("boolean"!=typeof t?e.log.error("Invalid value for repeat",t):f.repeat_=t),f.repeat_}}),f.currentItem(i),f},p=function(e,t){y(this,e,t)};return(e.registerPlugin||e.plugin)("playlist",p),p});