12 // Sequences |
12 // Sequences |
13 this.allSequencesData = []; |
13 this.allSequencesData = []; |
14 this.sequences = []; |
14 this.sequences = []; |
15 |
15 |
16 // Popcorn objects |
16 // Popcorn objects |
17 this.videoDivIdName = ""; |
17 this.videoDivId = ""; |
18 this.videoExt = ""; |
18 this.videoExt = ""; |
19 this.preferOgg = true; // debug |
19 this.preferOgg = true; // debug |
20 this.popSeq = null; |
20 this.popSeq = null; |
21 |
21 |
22 // Controls |
22 // Controls |
23 this.playButton = null; |
23 this.playButton = null; |
24 //this.hd = true; |
24 this.progressCurrent = null; |
|
25 this.progressDuration = null; |
25 this.hd = false; |
26 this.hd = false; |
26 this.seekTime = 0.0; |
27 this.seekTime = 0.0; |
27 |
28 |
28 // Tools |
29 // Tools |
29 this.logiEnable = true; |
30 this.logiEnable = true; |
31 |
32 |
32 // -------------------------------------------------------------------------------------------------------------------- |
33 // -------------------------------------------------------------------------------------------------------------------- |
33 // Functions |
34 // Functions |
34 // -------------------------------------------------------------------------------------------------------------------- |
35 // -------------------------------------------------------------------------------------------------------------------- |
35 |
36 |
36 this.init = function(videoDivIdName, playButton, jsonFile, preferOgg) |
37 this.init = function(videoDivId, playButtonId, progressCurrentId, progressDurationId, jsonFile, preferOgg) |
37 { |
38 { |
38 this.videoDivIdName = videoDivIdName; |
39 this.videoDivId = videoDivId; |
39 this.preferOgg = preferOgg; |
40 this.preferOgg = preferOgg; |
40 this.playButton = $(playButton).get(0); |
41 |
|
42 // Control |
|
43 this.playButton = $("#" + playButtonId).get(0); |
|
44 this.progressCurrent = $("#" + progressCurrentId); |
|
45 this.progressDuration = $("#" + progressDurationId); |
41 |
46 |
42 // Video extention |
47 // Video extention |
43 this.videoExt = this.getSupportedVideoExt(); |
48 this.videoExt = this.getSupportedVideoExt(); |
44 if (this.videoExt === "") { |
49 if (this.videoExt === "") { |
45 this.loge("your browser don't support HTML5 videos"); |
50 this.loge("your browser don't support HTML5 videos"); |
122 |
127 |
123 this.logi("choosed sequences:"); |
128 this.logi("choosed sequences:"); |
124 for (i = 0; i < this.sequences.length; ++i) { |
129 for (i = 0; i < this.sequences.length; ++i) { |
125 this.logi(this.sequenceToString(i)); |
130 this.logi(this.sequenceToString(i)); |
126 } |
131 } |
127 |
|
128 // debug |
|
129 var message = $("#message"); |
|
130 if (message !== undefined && this.sequences.length > 0) { |
|
131 if (this.sequences[0].src.search("720") >= 0) { |
|
132 message.html("720"); |
|
133 } else if (this.sequences[0].src.search("480") >= 0) { |
|
134 message.html("480"); |
|
135 } else if (this.sequences[0].src.search("360") >= 0) { |
|
136 message.html("360"); |
|
137 } else { |
|
138 message.html("???"); |
|
139 } |
|
140 } |
|
141 |
|
142 }; |
132 }; |
143 |
133 |
144 this.initPopSequence = function() |
134 this.initPopSequence = function() |
145 { |
135 { |
146 var self = this; |
136 var self = this; |
147 |
137 |
148 // Create the popcorn sequencer |
138 // Create the popcorn sequencer |
149 self.popSeq = Popcorn.sequence(self.videoDivIdName, self.sequences); |
139 self.popSeq = Popcorn.sequence(self.videoDivId, self.sequences); |
150 |
140 |
151 for (var i = 0; i < self.sequences.length; ++i) { |
141 for (var i = 0; i < self.sequences.length; ++i) { |
152 |
142 |
153 var pop = self.popSeq.eq(i); |
143 var pop = self.popSeq.eq(i); |
154 |
144 |
167 self.displayPlayButton(true); |
157 self.displayPlayButton(true); |
168 self.logi("pause sequence: " + self.sequenceToString(self.popSeq.active)); |
158 self.logi("pause sequence: " + self.sequenceToString(self.popSeq.active)); |
169 }); |
159 }); |
170 |
160 |
171 self.listenEvent(pop, "timeupdate", false, function() { |
161 self.listenEvent(pop, "timeupdate", false, function() { |
172 if (!self.iOS) { |
162 // Update the current time position |
173 //self.logi("current: " + self.getCurrentPop().currentTime()); |
163 $(self.progressCurrent).html(self.secondsToTime(self.popSeq.currentTime())); |
174 } |
|
175 }); |
164 }); |
176 |
165 |
177 self.listenEvent(pop, "canplaythrough", true, function() { |
166 self.listenEvent(pop, "canplaythrough", true, function() { |
178 }); |
167 }); |
179 } |
168 } |
180 |
169 |
181 self.popSeq.on("loadedmetadata", function() { |
170 self.popSeq.on("loadedmetadata", function() { |
182 |
171 |
183 self.playerIsReady = true; |
172 self.playerIsReady = true; |
|
173 |
|
174 // Set total duration |
|
175 $(self.progressDuration).html(self.secondsToTime(self.popSeq.duration())); |
184 |
176 |
185 if (!self.iOS) { |
177 if (!self.iOS) { |
186 // Automatic play |
178 // Automatic play |
187 self.ctrlPlay(); |
179 self.ctrlPlay(); |
188 |
180 |
242 // Pause |
237 // Pause |
243 this.popSeq.pause(); |
238 this.popSeq.pause(); |
244 } |
239 } |
245 }; |
240 }; |
246 |
241 |
247 this.ctrlForward = function() |
242 this.ctrlNext = function() |
248 { |
243 { |
249 if (!this.playerIsReady) { |
244 if (!this.playerIsReady) { |
250 // The video are not ready |
245 // The video are not ready |
251 this.logi("can't play, the player is not ready"); |
246 this.logi("can't play, the player is not ready"); |
252 return; |
247 return; |
253 } |
248 } |
254 |
249 |
255 // Seek 1 second forward |
250 if (this.popSeq.active == this.sequences.length - 1) { |
256 this.popSeq.jumpTo(this.popSeq.currentTime() + 1); |
251 // We are at the last video |
257 }; |
252 return; |
258 |
253 } |
259 this.ctrlBackward = function() |
254 |
|
255 // Go to the next video |
|
256 var jumpTime = this.popSeq.durationSeqs(this.popSeq.active + 1); |
|
257 this.popSeq.jumpTo(jumpTime); |
|
258 }; |
|
259 |
|
260 this.ctrlPrev = function() |
260 { |
261 { |
261 if (!this.playerIsReady) { |
262 if (!this.playerIsReady) { |
262 // The video are not ready |
263 // The video are not ready |
263 this.logi("can't play, the player is not ready"); |
264 this.logi("can't play, the player is not ready"); |
264 return; |
265 return; |
265 } |
266 } |
266 |
267 |
267 // Seek 1 second backward |
268 var videoIndex = this.popSeq.active; |
268 this.popSeq.jumpTo(this.popSeq.currentTime() - 1); |
269 if (videoIndex !== 0) { |
|
270 // If we are a less than 1 sec from the sequence start, we just to the prev sequence |
|
271 // else we jump to the start of the current sequence |
|
272 var jumpTimeStartCurrent = this.popSeq.durationSeqs(videoIndex); |
|
273 if (this.popSeq.currentTime() - jumpTimeStartCurrent < 1) { |
|
274 --videoIndex; |
|
275 } |
|
276 } |
|
277 |
|
278 // Go to the next video |
|
279 var jumpTime = this.popSeq.durationSeqs(videoIndex); |
|
280 this.popSeq.jumpTo(jumpTime); |
269 }; |
281 }; |
270 |
282 |
271 this.ctrlFullScreen = function() |
283 this.ctrlFullScreen = function() |
272 { |
284 { |
273 if (!this.playerIsReady) { |
285 if (!this.playerIsReady) { |
363 this.random = function(min, max) |
375 this.random = function(min, max) |
364 { |
376 { |
365 return Math.floor((Math.random()*(max-min))+min); |
377 return Math.floor((Math.random()*(max-min))+min); |
366 }; |
378 }; |
367 |
379 |
|
380 this.secondsToTime = function(sec) |
|
381 { |
|
382 var minutes = Math.floor(sec / 60); |
|
383 var seconds = Math.floor(sec - minutes * 60); |
|
384 if (seconds < 10) { |
|
385 seconds = "0" + seconds; |
|
386 } |
|
387 return "" + minutes + "'" + seconds + "''"; |
|
388 }; |
|
389 |
368 this.sequenceToString = function(index) |
390 this.sequenceToString = function(index) |
369 { |
391 { |
370 return JSON.stringify(this.sequences[index]); |
392 return JSON.stringify(this.sequences[index]); |
371 }; |
393 }; |
372 |
394 |