web/static/res/js/incplayer.js
changeset 48 d92196482ad9
parent 47 dbd46ed42b0d
child 49 cb8403125d4d
equal deleted inserted replaced
47:dbd46ed42b0d 48:d92196482ad9
    94 
    94 
    95 	this.choosePopSequence = function(words)
    95 	this.choosePopSequence = function(words)
    96 	{
    96 	{
    97 		this.sequences = [];
    97 		this.sequences = [];
    98 		var videos = this.allSequencesData.videos;
    98 		var videos = this.allSequencesData.videos;
    99 		this.sequences.push(this.getRandomVideos(words[0]));		
    99 
   100 		this.sequences.push(this.getRandomVideos(words[1]));		
   100 		// Choose first video
   101 		this.sequences.push(this.getRandomVideos(words[2]));		
   101 		var v1 = this.getRandomVideos(words[0]);
       
   102 		this.sequences.push(v1);		
       
   103 
       
   104 		var v2, v3;
       
   105 
       
   106 		// Choose second video
       
   107 		do {
       
   108 			v2 = this.getRandomVideos(words[1])	;
       
   109 		} while (v2.src == v1.src);
       
   110 		this.sequences.push(v2);		
       
   111 
       
   112 		// Choose third video
       
   113 		do {
       
   114 			v3 = this.getRandomVideos(words[2])	;
       
   115 		} while (v3.src == v1.src || v3.src == v2.src);
       
   116 		this.sequences.push(v3);		
   102 
   117 
   103 		// Set the video file name 
   118 		// Set the video file name 
   104 		var i;
   119 		var i;
   105 		for (i = 0; i < this.sequences.length; ++i) {
   120 		for (i = 0; i < this.sequences.length; ++i) {
   106 			var file = this.sequences[i];
   121 			var v = this.sequences[i];
   107 			
   122 			
   108 			// HD
   123 			// HD
   109 			if(this.hd) {
   124 			if(this.hd) {
   110 				file += "hd"; 
   125 				v.src += "hd"; 
   111 			}
   126 			}
   112 
   127 
   113 			// Extention
   128 			// Extention
   114 			file += "." + /*this.videoExt*/ "mp4"; // todo
   129 			v.src += "." + /*this.videoExt*/ "mp4"; // todo
   115 
   130 
   116 			// Set the final file
   131 			// Set the final file
   117 			this.sequences[i] = file;
   132 			this.sequences[i] = v;
   118 		}
   133 		}
   119 
   134 
   120 		for (i = 0; i < this.sequences.length; ++i) {
   135 		for (i = 0; i < this.sequences.length; ++i) {
   121 			this.sequences[i] = { src: this.sequences[i], in: 0, out: -1 };
   136 			var seq = this.sequences[i];
   122 		}
   137 
   123 
   138 			var integer = Math.floor(seq.duration);
       
   139 			var decimal = Math.floor((seq.duration - integer) * 100);
       
   140 			var duration = integer * 60 + decimal;
       
   141 
       
   142 			this.sequences[i] = { src: seq.src, in: 0, out: duration };
       
   143 		}
   124 		
   144 		
   125 		this.logi("choosed sequences:");
   145 		this.logi("choosed sequences:");
   126 		for (i = 0; i < this.sequences.length; ++i) {
   146 		for (i = 0; i < this.sequences.length; ++i) {
   127 			this.logi(this.sequenceToString(i));
   147 			this.logi(this.sequenceToString(i));
   128 		}
   148 		}
   137 		for (var i = 0; i < this.allSequencesData.videos.length; ++i) {
   157 		for (var i = 0; i < this.allSequencesData.videos.length; ++i) {
   138 			var video = this.allSequencesData.videos[i];
   158 			var video = this.allSequencesData.videos[i];
   139 
   159 
   140 			// We push has many time the url that the score for the word
   160 			// We push has many time the url that the score for the word
   141 			for (var j = 0; j < video.scoreWord[index]; ++j) {
   161 			for (var j = 0; j < video.scoreWord[index]; ++j) {
   142 				videos.push(video.src);
   162 				videos.push(video);
   143 			}
   163 			}
   144 		}
   164 		}
   145 
   165 
   146 		return videos[this.random(0, videos.length)];
   166 		return videos[this.random(0, videos.length)];
   147 	}
   167 	}
   182 				self.logi("pause sequence: " + self.sequenceToString(self.popSeq.active));
   202 				self.logi("pause sequence: " + self.sequenceToString(self.popSeq.active));
   183 			});			
   203 			});			
   184 
   204 
   185 			self.listenEvent(pop, "timeupdate", false, function() {
   205 			self.listenEvent(pop, "timeupdate", false, function() {
   186 				// Update the current time position
   206 				// Update the current time position
   187 				$(self.progressCurrent).html(self.secondsToTime(self.popSeq.currentTime()));
   207 				var currentTime = self.popSeq.currentTime();
       
   208 				$(self.progressCurrent).html(self.secondsToTime(currentTime));
       
   209 
       
   210 				// Detect vsquence end
       
   211 				if (self.popSeq.active == 2 && currentTime >= self.popSeq.duration()) {
       
   212 					setTimeout(function() { 
       
   213 								location.href = "transition.html";
       
   214 							}, 2000);
       
   215 
       
   216 				}
   188 			});
   217 			});
   189 
   218 
   190 			self.listenEvent(pop, "canplaythrough", true, function() {
   219 			self.listenEvent(pop, "canplaythrough", true, function() {
   191 			});
   220 			});
   192 		}
   221 		}
   195 
   224 
   196 			self.playerIsReady = true;
   225 			self.playerIsReady = true;
   197 
   226 
   198 			// todo
   227 			// todo
   199 			// Set total duration
   228 			// Set total duration
   200 			//$(self.progressDuration).html(self.secondsToTime(self.popSeq.duration()));			
   229 			$(self.progressDuration).html(self.secondsToTime(self.popSeq.duration()));			
   201 
   230 
   202 			if (!self.iOS) {
   231 			if (!self.iOS) {
   203 				// Automatic play
   232 				// Automatic play
   204 				self.ctrlPlay();
   233 				self.ctrlPlay();
   205 			}
   234 			}
   211 
   240 
   212 		self.popSeq.on("cycle", function() {
   241 		self.popSeq.on("cycle", function() {
   213 		});
   242 		});
   214 
   243 
   215 		self.popSeq.on("ended", function() {
   244 		self.popSeq.on("ended", function() {
   216 			// todo
       
   217 			location.href = "transition.html";			
       
   218 		});
   245 		});
   219 
   246 
   220 	};
   247 	};
   221 
   248 
   222 	this.listenEvent = function(pop, event, unlisten, func)
   249 	this.listenEvent = function(pop, event, unlisten, func)