1+ /**
2+ * videojs-time-offset
3+ * @version 0.1.0
4+ * @copyright 2016 Can Küçükyılmaz <can@vngrs.com>
5+ * @license MIT
6+ */
7+ ( function ( f ) { if ( typeof exports === "object" && typeof module !== "undefined" ) { module . exports = f ( ) } else if ( typeof define === "function" && define . amd ) { define ( [ ] , f ) } else { var g ; if ( typeof window !== "undefined" ) { g = window } else if ( typeof global !== "undefined" ) { g = global } else if ( typeof self !== "undefined" ) { g = self } else { g = this } g . videojsTimeOffset = f ( ) } } ) ( function ( ) { var define , module , exports ; return ( function e ( t , n , r ) { function s ( o , u ) { if ( ! n [ o ] ) { if ( ! t [ o ] ) { var a = typeof require == "function" && require ; if ( ! u && a ) return a ( o , ! 0 ) ; if ( i ) return i ( o , ! 0 ) ; var f = new Error ( "Cannot find module '" + o + "'" ) ; throw f . code = "MODULE_NOT_FOUND" , f } var l = n [ o ] = { exports :{ } } ; t [ o ] [ 0 ] . call ( l . exports , function ( e ) { var n = t [ o ] [ 1 ] [ e ] ; return s ( n ?n :e ) } , l , l . exports , e , t , n , r ) } return n [ o ] . exports } var i = typeof require == "function" && require ; for ( var o = 0 ; o < r . length ; o ++ ) s ( r [ o ] ) ; return s } ) ( { 1 :[ function ( require , module , exports ) {
8+ ( function ( global ) {
9+ 'use strict' ;
10+
11+ Object . defineProperty ( exports , '__esModule' , {
12+ value : true
13+ } ) ;
14+
15+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { 'default' : obj } ; }
16+
17+ var _videoJs = ( typeof window !== "undefined" ? window [ 'videojs' ] : typeof global !== "undefined" ? global [ 'videojs' ] : null ) ;
18+
19+ var _videoJs2 = _interopRequireDefault ( _videoJs ) ;
20+
21+ // Default options for the plugin.
22+ var defaults = {
23+ start : 0 ,
24+ end : 0 ,
25+ page : 1 ,
26+ perPageInMinutes : 0
27+ } ;
28+
29+ /**
30+ * for fixing buffer status overflow issue
31+ */
32+ var addStyle = function addStyle ( ) {
33+ /**
34+ * Style already included, only include once
35+ */
36+ if ( document . getElementById ( 'vjs-time-offset-style' ) ) {
37+ return false ;
38+ }
39+
40+ var css = '\n .vjs-time-offset .vjs-load-progress {\n overflow: hidden;\n };\n ' ;
41+ var head = document . head || document . getElementsByTagName ( 'head' ) [ 0 ] ;
42+ var style = document . createElement ( 'style' ) ;
43+
44+ style . id = 'vjs-time-offset-style' ;
45+ style . type = 'text/css' ;
46+ if ( style . styleSheet ) {
47+ style . styleSheet . cssText = css ;
48+ } else {
49+ style . appendChild ( document . createTextNode ( css ) ) ;
50+ }
51+
52+ head . appendChild ( style ) ;
53+ } ;
54+
55+ /**
56+ * Function to invoke when the player is ready.
57+ *
58+ * This is a great place for your plugin to initialize itself. When this
59+ * function is called, the player will have its DOM and child components
60+ * in place.
61+ *
62+ * @function onPlayerReady
63+ * @param {Player } player
64+ * @param {Object } [options={}]
65+ */
66+ var onPlayerReady = function onPlayerReady ( player , options ) {
67+ var offsetStart = undefined ;
68+ var offsetEnd = undefined ;
69+ var computedDuration = undefined ;
70+
71+ /**
72+ * calc offsetStart and offsetEnd based on options
73+ * if page params is setted use page values, Otherwise use defaults
74+ * default perPageInMinutes based on minutes, convert to seconds
75+ */
76+ options . perPageInMinutes = options . perPageInMinutes * 60 ;
77+
78+ // page is natural number convert it to integer
79+ options . perPage = options . perPage - 1 ;
80+
81+ if ( options . start > 0 ) {
82+ offsetStart = options . start ;
83+ } else {
84+ offsetStart = options . page * options . perPageInMinutes ;
85+ }
86+
87+ if ( options . end > 0 ) {
88+ offsetEnd = options . end ;
89+ } else {
90+ offsetEnd = ( options . page + 1 ) * options . perPageInMinutes ;
91+ }
92+
93+ computedDuration = offsetEnd - offsetStart ;
94+
95+ /**
96+ * For monkey patching take references of original methods
97+ * We will override original methods
98+ */
99+ var __monkey__ = {
100+ currentTime : player . currentTime ,
101+ remainingTime : player . remainingTime ,
102+ duration : player . duration
103+ } ;
104+
105+ player . addClass ( 'vjs-time-offset' ) ;
106+
107+ addStyle ( ) ;
108+
109+ player . remainingTime = function ( ) {
110+ return player . duration ( ) - player . currentTime ( ) ;
111+ } ;
112+
113+ player . duration = function ( ) {
114+ for ( var _len = arguments . length , args = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
115+ args [ _key ] = arguments [ _key ] ;
116+ }
117+
118+ if ( offsetEnd > 0 ) {
119+ __monkey__ . duration . apply ( player , args ) ;
120+ return computedDuration ;
121+ }
122+
123+ return __monkey__ . duration . apply ( player , args ) - offsetStart ;
124+ } ;
125+
126+ player . originalDuration = function ( ) {
127+ for ( var _len2 = arguments . length , args = Array ( _len2 ) , _key2 = 0 ; _key2 < _len2 ; _key2 ++ ) {
128+ args [ _key2 ] = arguments [ _key2 ] ;
129+ }
130+
131+ return __monkey__ . duration . apply ( player , args ) ;
132+ } ;
133+
134+ player . currentTime = function ( seconds ) {
135+ if ( typeof seconds !== 'undefined' ) {
136+ seconds = seconds + offsetStart ;
137+
138+ return __monkey__ . currentTime . call ( player , seconds ) ;
139+ }
140+
141+ var current = __monkey__ . currentTime . call ( player ) - offsetStart ;
142+
143+ if ( current < 0 ) {
144+ player . currentTime ( 0 ) ;
145+ return 0 ;
146+ }
147+ return current ;
148+ } ;
149+
150+ /**
151+ * When user clicks play button after partition finished
152+ * start from beginning of partition
153+ */
154+ player . on ( 'play' , function ( ) {
155+ var remaining = player . remainingTime ( ) ;
156+
157+ if ( remaining <= 0 ) {
158+ player . currentTime ( 0 ) ;
159+ player . play ( ) ;
160+ }
161+ } ) ;
162+
163+ player . on ( 'loadedmetadata' , function ( ) {
164+ var current = player . currentTime ( ) ;
165+ var originalDuration = player . originalDuration ( ) ;
166+
167+ // if setted end value isn't correct, Fix IT
168+ // it shouldn't be bigger than video length
169+ if ( offsetEnd > originalDuration ) {
170+ computedDuration = originalDuration - offsetStart ;
171+ }
172+
173+ // if setted start value isn't correct, Fix IT
174+ // it shouldn't be bigger than video length
175+ if ( offsetStart > originalDuration ) {
176+ offsetStart = 0 ;
177+ computedDuration = originalDuration ;
178+ }
179+
180+ if ( current < 0 ) {
181+ player . currentTime ( 0 ) ;
182+ }
183+ } ) ;
184+
185+ player . on ( 'timeupdate' , function ( ) {
186+ var remaining = player . remainingTime ( ) ;
187+
188+ if ( remaining <= 0 ) {
189+ player . pause ( ) ;
190+ }
191+ } ) ;
192+ } ;
193+
194+ /**
195+ * A video.js plugin.
196+ *
197+ * In the plugin function, the value of `this` is a video.js `Player`
198+ * instance. You cannot rely on the player being in a "ready" state here,
199+ * depending on how the plugin is invoked. This may or may not be important
200+ * to you; if not, remove the wait for "ready"!
201+ *
202+ * @function time-offset
203+ * @param {Object } [options={}]
204+ * An object of options left to the plugin author to define.
205+ */
206+ var timeOffset = function timeOffset ( options ) {
207+ var _this = this ;
208+
209+ this . ready ( function ( ) {
210+ onPlayerReady ( _this , _videoJs2 [ 'default' ] . mergeOptions ( defaults , options ) ) ;
211+ } ) ;
212+ } ;
213+
214+ // Register the plugin with video.js.
215+ _videoJs2 [ 'default' ] . plugin ( 'timeOffset' , timeOffset ) ;
216+
217+ // Include the version number.
218+ timeOffset . VERSION = '0.0.1' ;
219+
220+ exports [ 'default' ] = timeOffset ;
221+ module . exports = exports [ 'default' ] ;
222+ } ) . call ( this , typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : { } )
223+ } , { } ] } , { } , [ 1 ] ) ( 1 )
224+ } ) ;
0 commit comments