duration update moved to parser. fix for broken tests.
Showing
2 changed files
with
17 additions
and
17 deletions
... | @@ -284,8 +284,7 @@ | ... | @@ -284,8 +284,7 @@ |
284 | 284 | ||
285 | // the manifest is empty until the parse stream begins delivering data | 285 | // the manifest is empty until the parse stream begins delivering data |
286 | this.manifest = { | 286 | this.manifest = { |
287 | allowCache: true, | 287 | allowCache: true |
288 | totalDuration: 0 | ||
289 | }; | 288 | }; |
290 | 289 | ||
291 | // update the manifest with the m3u8 entry from the parse stream | 290 | // update the manifest with the m3u8 entry from the parse stream |
... | @@ -373,6 +372,17 @@ | ... | @@ -373,6 +372,17 @@ |
373 | return; | 372 | return; |
374 | } | 373 | } |
375 | this.manifest.targetDuration = entry.duration; | 374 | this.manifest.targetDuration = entry.duration; |
375 | }, | ||
376 | 'endlist': function() { | ||
377 | var calculatedDuration = 0; | ||
378 | for(var i = 0; i < this.manifest.segments.length; i++) { | ||
379 | if(this.manifest.segments[i].duration) { | ||
380 | calculatedDuration += this.manifest.segments[i].duration; | ||
381 | } else if (this.manifest.targetDuration) { | ||
382 | calculatedDuration += this.manifest.targetDuration; | ||
383 | } | ||
384 | } | ||
385 | this.trigger('durationUpdate', parseInt(calculatedDuration)); | ||
376 | } | 386 | } |
377 | })[entry.tagType] || noop).call(self); | 387 | })[entry.tagType] || noop).call(self); |
378 | }, | 388 | }, | ... | ... |
... | @@ -28,7 +28,7 @@ var | ... | @@ -28,7 +28,7 @@ var |
28 | 28 | ||
29 | segmentXhr, | 29 | segmentXhr, |
30 | fillBuffer, | 30 | fillBuffer, |
31 | onLoadedManifest, | 31 | onDurationUpdate, |
32 | selectPlaylist; | 32 | selectPlaylist; |
33 | 33 | ||
34 | extname = (/[^#?]*(?:\/[^#?]*\.([^#?]*))/).exec(player.currentSrc()); | 34 | extname = (/[^#?]*(?:\/[^#?]*\.([^#?]*))/).exec(player.currentSrc()); |
... | @@ -67,18 +67,8 @@ var | ... | @@ -67,18 +67,8 @@ var |
67 | player.hls.currentMediaIndex = 0; | 67 | player.hls.currentMediaIndex = 0; |
68 | }; | 68 | }; |
69 | 69 | ||
70 | onLoadedManifest = function() { | 70 | onDurationUpdate = function(value) { |
71 | if(player.hls.manifest.totalDuration === 0) { | 71 | player.duration(value); |
72 | for(var i in player.hls.manifest.segments) { | ||
73 | var currentSegment = player.hls.manifest.segments[i]; | ||
74 | currentSegment.timeRange = {}; | ||
75 | currentSegment.timeRange.start = player.hls.manifest.totalDuration; | ||
76 | currentSegment.timeRange.end = currentSegment.timeRange.start + currentSegment.duration; | ||
77 | player.hls.manifest.totalDuration += currentSegment.duration; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | player.duration(player.hls.manifest.totalDuration); | ||
82 | }; | 72 | }; |
83 | 73 | ||
84 | /** | 74 | /** |
... | @@ -159,8 +149,7 @@ var | ... | @@ -159,8 +149,7 @@ var |
159 | }; | 149 | }; |
160 | player.on('loadedmetadata', fillBuffer); | 150 | player.on('loadedmetadata', fillBuffer); |
161 | player.on('timeupdate', fillBuffer); | 151 | player.on('timeupdate', fillBuffer); |
162 | player.on('loadedmanifest', onLoadedManifest); | 152 | |
163 | |||
164 | // download and process the manifest | 153 | // download and process the manifest |
165 | (function() { | 154 | (function() { |
166 | var xhr = new window.XMLHttpRequest(); | 155 | var xhr = new window.XMLHttpRequest(); |
... | @@ -171,6 +160,7 @@ var | ... | @@ -171,6 +160,7 @@ var |
171 | if (xhr.readyState === 4) { | 160 | if (xhr.readyState === 4) { |
172 | // readystate DONE | 161 | // readystate DONE |
173 | parser = new videojs.m3u8.Parser(); | 162 | parser = new videojs.m3u8.Parser(); |
163 | parser.on('durationUpdate', onDurationUpdate); | ||
174 | parser.push(xhr.responseText); | 164 | parser.push(xhr.responseText); |
175 | player.hls.manifest = parser.manifest; | 165 | player.hls.manifest = parser.manifest; |
176 | 166 | ... | ... |
-
Please register or sign in to post a comment