diff -r e5421b704368 -r 6cd5bc3dc7a2 web/static/res/js/incplayer.js --- a/web/static/res/js/incplayer.js Fri Nov 16 12:53:58 2012 +0100 +++ b/web/static/res/js/incplayer.js Sun Dec 09 19:59:03 2012 +0100 @@ -14,14 +14,15 @@ this.sequences = []; // Popcorn objects - this.videoDivIdName = ""; + this.videoDivId = ""; this.videoExt = ""; this.preferOgg = true; // debug this.popSeq = null; // Controls this.playButton = null; - //this.hd = true; + this.progressCurrent = null; + this.progressDuration = null; this.hd = false; this.seekTime = 0.0; @@ -33,11 +34,15 @@ // Functions // -------------------------------------------------------------------------------------------------------------------- - this.init = function(videoDivIdName, playButton, jsonFile, preferOgg) + this.init = function(videoDivId, playButtonId, progressCurrentId, progressDurationId, jsonFile, preferOgg) { - this.videoDivIdName = videoDivIdName; + this.videoDivId = videoDivId; this.preferOgg = preferOgg; - this.playButton = $(playButton).get(0); + + // Control + this.playButton = $("#" + playButtonId).get(0); + this.progressCurrent = $("#" + progressCurrentId); + this.progressDuration = $("#" + progressDurationId); // Video extention this.videoExt = this.getSupportedVideoExt(); @@ -124,21 +129,6 @@ for (i = 0; i < this.sequences.length; ++i) { this.logi(this.sequenceToString(i)); } - - // debug - var message = $("#message"); - if (message !== undefined && this.sequences.length > 0) { - if (this.sequences[0].src.search("720") >= 0) { - message.html("720"); - } else if (this.sequences[0].src.search("480") >= 0) { - message.html("480"); - } else if (this.sequences[0].src.search("360") >= 0) { - message.html("360"); - } else { - message.html("???"); - } - } - }; this.initPopSequence = function() @@ -146,7 +136,7 @@ var self = this; // Create the popcorn sequencer - self.popSeq = Popcorn.sequence(self.videoDivIdName, self.sequences); + self.popSeq = Popcorn.sequence(self.videoDivId, self.sequences); for (var i = 0; i < self.sequences.length; ++i) { @@ -169,9 +159,8 @@ }); self.listenEvent(pop, "timeupdate", false, function() { - if (!self.iOS) { - //self.logi("current: " + self.getCurrentPop().currentTime()); - } + // Update the current time position + $(self.progressCurrent).html(self.secondsToTime(self.popSeq.currentTime())); }); self.listenEvent(pop, "canplaythrough", true, function() { @@ -182,6 +171,9 @@ self.playerIsReady = true; + // Set total duration + $(self.progressDuration).html(self.secondsToTime(self.popSeq.duration())); + if (!self.iOS) { // Automatic play self.ctrlPlay(); @@ -193,7 +185,12 @@ } // Unlisten event - self.popSeq.off("loadedmetadata"); + self.popSeq.off("loadedmetadata"); + + // Call the resize object + if (incResize !== undefined) { + incResize.resizeElements(); + } self.logi("the player is ready"); }); @@ -216,8 +213,6 @@ }); }; - //this. - this.getCurrentPop = function() { var index = this.popSeq.active; @@ -244,7 +239,7 @@ } }; - this.ctrlForward = function() + this.ctrlNext = function() { if (!this.playerIsReady) { // The video are not ready @@ -252,11 +247,17 @@ return; } - // Seek 1 second forward - this.popSeq.jumpTo(this.popSeq.currentTime() + 1); + if (this.popSeq.active == this.sequences.length - 1) { + // We are at the last video + return; + } + + // Go to the next video + var jumpTime = this.popSeq.durationSeqs(this.popSeq.active + 1); + this.popSeq.jumpTo(jumpTime); }; - this.ctrlBackward = function() + this.ctrlPrev = function() { if (!this.playerIsReady) { // The video are not ready @@ -264,8 +265,19 @@ return; } - // Seek 1 second backward - this.popSeq.jumpTo(this.popSeq.currentTime() - 1); + var videoIndex = this.popSeq.active; + if (videoIndex !== 0) { + // If we are a less than 1 sec from the sequence start, we just to the prev sequence + // else we jump to the start of the current sequence + var jumpTimeStartCurrent = this.popSeq.durationSeqs(videoIndex); + if (this.popSeq.currentTime() - jumpTimeStartCurrent < 1) { + --videoIndex; + } + } + + // Go to the next video + var jumpTime = this.popSeq.durationSeqs(videoIndex); + this.popSeq.jumpTo(jumpTime); }; this.ctrlFullScreen = function() @@ -365,6 +377,16 @@ return Math.floor((Math.random()*(max-min))+min); }; + this.secondsToTime = function(sec) + { + var minutes = Math.floor(sec / 60); + var seconds = Math.floor(sec - minutes * 60); + if (seconds < 10) { + seconds = "0" + seconds; + } + return "" + minutes + "'" + seconds + "''"; + }; + this.sequenceToString = function(index) { return JSON.stringify(this.sequences[index]);