web/static/res/js/incplayer.js
changeset 46 542252e0c615
parent 36 6cd5bc3dc7a2
child 47 dbd46ed42b0d
equal deleted inserted replaced
45:f7bfdc49982b 46:542252e0c615
    57 			this.logi("we are on iOS");
    57 			this.logi("we are on iOS");
    58 		}
    58 		}
    59 
    59 
    60 		// Load all sequences data
    60 		// Load all sequences data
    61 		this.allSequencesData = this.loadJson(jsonFile);
    61 		this.allSequencesData = this.loadJson(jsonFile);
    62 		this.logi("sequences in part1: " + (this.allSequencesData.part1 !== undefined ? this.allSequencesData.part1.length : 0));
       
    63 		this.logi("sequences in part2: " + (this.allSequencesData.part2 !== undefined ? this.allSequencesData.part2.length : 0));
       
    64 		this.logi("sequences in part3: " + (this.allSequencesData.part3 !== undefined ? this.allSequencesData.part3.length : 0));
       
    65 
    62 
    66 		this.initDone = true;
    63 		this.initDone = true;
    67 		return true;
    64 		return true;
    68 	};
    65 	};
    69 
    66 
    76 			this.sequences = [];
    73 			this.sequences = [];
    77 			this.popSeq.remove();
    74 			this.popSeq.remove();
    78 		}		
    75 		}		
    79 	};
    76 	};
    80 
    77 
    81 	this.createPopSequence = function()
    78 	this.createPopSequence = function(words)
    82 	{
    79 	{
    83 		if (!this.initDone) {
    80 		if (!this.initDone) {
    84 			this.loge("incplayer not initialized");
    81 			this.loge("incplayer not initialized");
    85 			return;
    82 			return;
    86 		}
    83 		}
    87 
    84 
    88 		// Delete previous popcorn objects
    85 		// Delete previous popcorn objects
    89 		this.destroySequence();
    86 		this.destroySequence();
    90 
    87 
    91 		// Choose the 3 video
    88 		// Choose the 3 video
    92 		this.choosePopSequence();
    89 		this.choosePopSequence(words);
    93 
    90 
    94 		// And cerate the popcorn sequence
    91 		// And cerate the popcorn sequence
    95 		this.initPopSequence();
    92 		this.initPopSequence();
    96 	};
    93 	};
    97 
    94 
    98 	this.choosePopSequence = function()
    95 	this.choosePopSequence = function(words)
    99 	{
    96 	{
   100 		this.sequences = [];
    97 		this.sequences = [];
   101 		if (this.allSequencesData.part1 !== undefined && this.allSequencesData.part1.length) {
    98 		var videos = this.allSequencesData.videos;
   102 			this.sequences.push(this.allSequencesData.part1[this.random(0, this.allSequencesData.part1.length)]);			
    99 		this.sequences.push(this.getRandomVideos(words[0]));		
   103 		}
   100 		this.sequences.push(this.getRandomVideos(words[1]));		
   104 		if (this.allSequencesData.part2 !== undefined && this.allSequencesData.part2.length) {
   101 		this.sequences.push(this.getRandomVideos(words[2]));		
   105 			this.sequences.push(this.allSequencesData.part2[this.random(0, this.allSequencesData.part2.length)]);
       
   106 		}
       
   107 		if (this.allSequencesData.part3 !== undefined && this.allSequencesData.part3.length) {
       
   108 			this.sequences.push(this.allSequencesData.part3[this.random(0, this.allSequencesData.part3.length)]);
       
   109 		}
       
   110 
   102 
   111 		// Set the video file name 
   103 		// Set the video file name 
   112 		var i;
   104 		var i;
   113 		for (i = 0; i < this.sequences.length; ++i) {
   105 		for (i = 0; i < this.sequences.length; ++i) {
   114 			var file = this.sequences[i].src;
   106 			var file = this.sequences[i];
   115 			
   107 			
   116 			// HD
   108 			// HD
   117 			if(this.hd) {
   109 			if(this.hd) {
   118 				file += "hd"; 
   110 				file += "hd"; 
   119 			}
   111 			}
   120 
   112 
   121 			// Extention
   113 			// Extention
   122 			file += "." + this.videoExt;
   114 			file += "." + /*this.videoExt*/ "mp4"; // todo
   123 
   115 
   124 			// Set the final file
   116 			// Set the final file
   125 			this.sequences[i].src = file;
   117 			this.sequences[i] = file;
   126 		}
   118 		}
       
   119 
       
   120 		for (i = 0; i < this.sequences.length; ++i) {
       
   121 			this.sequences[i] = { src: this.sequences[i], in: 0, out: -1 };
       
   122 		}
       
   123 
   127 		
   124 		
   128 		this.logi("choosed sequences:");
   125 		this.logi("choosed sequences:");
   129 		for (i = 0; i < this.sequences.length; ++i) {
   126 		for (i = 0; i < this.sequences.length; ++i) {
   130 			this.logi(this.sequenceToString(i));
   127 			this.logi(this.sequenceToString(i));
   131 		}
   128 		}
   132 	};
   129 	};
   133 
   130 
       
   131 	this.getRandomVideos = function(word)
       
   132 	{
       
   133 		var index = this.getWordIndex(word);
       
   134 		var videos = [];
       
   135 
       
   136 		// Get all video affected by this word
       
   137 		for (var i = 0; i < this.allSequencesData.videos.length; ++i) {
       
   138 			var video = this.allSequencesData.videos[i];
       
   139 
       
   140 			// We push has many time the url that the score for the word
       
   141 			for (var j = 0; j < video.scoreWord[index]; ++j) {
       
   142 				videos.push(video.src);
       
   143 			}
       
   144 		}
       
   145 
       
   146 		return videos[this.random(0, videos.length)];
       
   147 	}
       
   148 
       
   149 	this.getWordIndex = function(word)
       
   150 	{
       
   151 		var words = this.allSequencesData.mots;
       
   152 		for (var i = 0; i < words.length; ++i) {
       
   153 			if (words[i] == word) {
       
   154 				return i;
       
   155 			}
       
   156 		}
       
   157 		console.log("getWordIndex erreur");
       
   158 		return -1;
       
   159 	};
       
   160 
   134 	this.initPopSequence = function()
   161 	this.initPopSequence = function()
   135 	{
   162 	{
   136 		var self = this;
   163 		var self = this;
   137 
   164 
   138 		// Create the popcorn sequencer
   165 		// Create the popcorn sequencer
   142 			
   169 			
   143 			var pop = self.popSeq.eq(i);
   170 			var pop = self.popSeq.eq(i);
   144 
   171 
   145 			// Hide controls
   172 			// Hide controls
   146 			pop.controls(false);
   173 			pop.controls(false);
   147 
       
   148 			// Mute (debug)
       
   149 			pop.mute();
       
   150 
   174 
   151 			self.listenEvent(pop, "playing", false, function() {
   175 			self.listenEvent(pop, "playing", false, function() {
   152 				self.displayPlayButton(false);
   176 				self.displayPlayButton(false);
   153 				self.logi("play sequence: " + self.sequenceToString(self.popSeq.active));
   177 				self.logi("play sequence: " + self.sequenceToString(self.popSeq.active));
   154 			});
   178 			});
   169 
   193 
   170 		self.popSeq.on("loadedmetadata", function() {
   194 		self.popSeq.on("loadedmetadata", function() {
   171 
   195 
   172 			self.playerIsReady = true;
   196 			self.playerIsReady = true;
   173 
   197 
       
   198 			// todo
   174 			// Set total duration
   199 			// Set total duration
   175 			$(self.progressDuration).html(self.secondsToTime(self.popSeq.duration()));			
   200 			//$(self.progressDuration).html(self.secondsToTime(self.popSeq.duration()));			
   176 
   201 
   177 			if (!self.iOS) {
   202 			if (!self.iOS) {
   178 				// Automatic play
   203 				// Automatic play
   179 				self.ctrlPlay();
   204 				self.ctrlPlay();
   180 
       
   181 				if (self.seekTime !== 0.0) {
       
   182 					self.popSeq.jumpTo(self.seekTime);
       
   183 					self.seekTime = 0.0;
       
   184 				}
       
   185 			}
   205 			}
   186 
   206 
   187 			// Unlisten event
   207 			// Unlisten event
   188 			self.popSeq.off("loadedmetadata");
   208 			self.popSeq.off("loadedmetadata");
   189 
       
   190 			// Call the resize object
       
   191 			if (incResize !== undefined) {
       
   192 				incResize.resizeElements();
       
   193 			}	
       
   194 
       
   195 			self.logi("the player is ready");
   209 			self.logi("the player is ready");
   196 		});	
   210 		});	
   197 
   211 
   198 		self.popSeq.on("cycle", function() {
   212 		self.popSeq.on("cycle", function() {
   199 			self.logi("CYCLE !");
       
   200 		});	
   213 		});	
   201 	};
   214 	};
   202 
   215 
   203 	this.listenEvent = function(pop, event, unlisten, func)
   216 	this.listenEvent = function(pop, event, unlisten, func)
   204 	{
   217 	{