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 |
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 { |