Update HLS:
dispose tech, playlist loader don't trigger loadedmetadata if there was an error no need for duration update workarounds, add duration to tech update all the tests remove irrelevant tests
Showing
4 changed files
with
40 additions
and
16 deletions
... | @@ -51,6 +51,7 @@ | ... | @@ -51,6 +51,7 @@ |
51 | var | 51 | var |
52 | loader = this, | 52 | loader = this, |
53 | media, | 53 | media, |
54 | mediaUpdateTimeout, | ||
54 | request, | 55 | request, |
55 | 56 | ||
56 | haveMetadata = function(error, xhr, url) { | 57 | haveMetadata = function(error, xhr, url) { |
... | @@ -88,7 +89,7 @@ | ... | @@ -88,7 +89,7 @@ |
88 | 89 | ||
89 | // refresh live playlists after a target duration passes | 90 | // refresh live playlists after a target duration passes |
90 | if (!loader.media().endList) { | 91 | if (!loader.media().endList) { |
91 | window.setTimeout(function() { | 92 | mediaUpdateTimeout = window.setTimeout(function() { |
92 | loader.trigger('mediaupdatetimeout'); | 93 | loader.trigger('mediaupdatetimeout'); |
93 | }, refreshDelay); | 94 | }, refreshDelay); |
94 | } | 95 | } |
... | @@ -104,6 +105,13 @@ | ... | @@ -104,6 +105,13 @@ |
104 | 105 | ||
105 | loader.state = 'HAVE_NOTHING'; | 106 | loader.state = 'HAVE_NOTHING'; |
106 | 107 | ||
108 | loader.dispose = function() { | ||
109 | if (request) { | ||
110 | request.abort(); | ||
111 | } | ||
112 | window.clearTimeout(mediaUpdateTimeout); | ||
113 | }; | ||
114 | |||
107 | /** | 115 | /** |
108 | * When called without any arguments, returns the currently | 116 | * When called without any arguments, returns the currently |
109 | * active media playlist. When called with a single argument, | 117 | * active media playlist. When called with a single argument, |
... | @@ -213,7 +221,9 @@ | ... | @@ -213,7 +221,9 @@ |
213 | haveMetadata(error, | 221 | haveMetadata(error, |
214 | this, | 222 | this, |
215 | parser.manifest.playlists[0].uri); | 223 | parser.manifest.playlists[0].uri); |
224 | if (!error) { | ||
216 | loader.trigger('loadedmetadata'); | 225 | loader.trigger('loadedmetadata'); |
226 | } | ||
217 | }); | 227 | }); |
218 | return loader.trigger('loadedplaylist'); | 228 | return loader.trigger('loadedplaylist'); |
219 | } | 229 | } | ... | ... |
... | @@ -153,6 +153,12 @@ var | ... | @@ -153,6 +153,12 @@ var |
153 | var | 153 | var |
154 | duration = 0, | 154 | duration = 0, |
155 | segment, | 155 | segment, |
156 | i; | ||
157 | |||
158 | if (!playlist) { | ||
159 | return 0; | ||
160 | } | ||
161 | |||
156 | i = (playlist.segments || []).length; | 162 | i = (playlist.segments || []).length; |
157 | 163 | ||
158 | // if present, use the duration specified in the playlist | 164 | // if present, use the duration specified in the playlist |
... | @@ -205,16 +211,8 @@ var | ... | @@ -205,16 +211,8 @@ var |
205 | * Update the player duration | 211 | * Update the player duration |
206 | */ | 212 | */ |
207 | updateDuration = function(playlist) { | 213 | updateDuration = function(playlist) { |
208 | var tech; | ||
209 | // update the duration | 214 | // update the duration |
210 | player.duration(totalDuration(playlist)); | 215 | player.duration(totalDuration(playlist)); |
211 | // tell the flash tech of the new duration | ||
212 | tech = player.el().querySelector('.vjs-tech'); | ||
213 | if(tech.vjs_setProperty) { | ||
214 | tech.vjs_setProperty('duration', player.duration()); | ||
215 | } | ||
216 | // manually fire the duration change | ||
217 | player.trigger('durationchange'); | ||
218 | }; | 216 | }; |
219 | 217 | ||
220 | /** | 218 | /** |
... | @@ -310,7 +308,8 @@ var | ... | @@ -310,7 +308,8 @@ var |
310 | } | 308 | } |
311 | 309 | ||
312 | // if no segments are available, do nothing | 310 | // if no segments are available, do nothing |
313 | if (!player.hls.playlists.media().segments) { | 311 | if (player.hls.playlists.state === "HAVE_NOTHING" || |
312 | !player.hls.playlists.media().segments) { | ||
314 | return; | 313 | return; |
315 | } | 314 | } |
316 | 315 | ||
... | @@ -456,12 +455,12 @@ videojs.Hls = videojs.Flash.extend({ | ... | @@ -456,12 +455,12 @@ videojs.Hls = videojs.Flash.extend({ |
456 | source = options.source, | 455 | source = options.source, |
457 | settings = player.options(); | 456 | settings = player.options(); |
458 | 457 | ||
458 | player.hls = this; | ||
459 | delete options.source; | 459 | delete options.source; |
460 | options.swf = settings.flash.swf; | 460 | options.swf = settings.flash.swf; |
461 | videojs.Flash.call(this, player, options, ready); | 461 | videojs.Flash.call(this, player, options, ready); |
462 | player.hls = {}; | ||
463 | options.source = source; | 462 | options.source = source; |
464 | videojs.Hls.prototype.src.call(player, options.source && options.source.src); | 463 | videojs.Hls.prototype.src.call(this, options.source && options.source.src); |
465 | } | 464 | } |
466 | }); | 465 | }); |
467 | 466 | ||
... | @@ -472,7 +471,7 @@ videojs.Hls.prototype.src = function(src) { | ... | @@ -472,7 +471,7 @@ videojs.Hls.prototype.src = function(src) { |
472 | source; | 471 | source; |
473 | 472 | ||
474 | if (src) { | 473 | if (src) { |
475 | mediaSource = new videojs.MediaSource(), | 474 | mediaSource = new videojs.MediaSource(); |
476 | source = { | 475 | source = { |
477 | src: videojs.URL.createObjectURL(mediaSource), | 476 | src: videojs.URL.createObjectURL(mediaSource), |
478 | type: "video/flv" | 477 | type: "video/flv" |
... | @@ -480,10 +479,25 @@ videojs.Hls.prototype.src = function(src) { | ... | @@ -480,10 +479,25 @@ videojs.Hls.prototype.src = function(src) { |
480 | player.hls.mediaSource = mediaSource; | 479 | player.hls.mediaSource = mediaSource; |
481 | initSource(player, mediaSource, src); | 480 | initSource(player, mediaSource, src); |
482 | this.ready(function() { | 481 | this.ready(function() { |
483 | this.el().querySelector('.vjs-tech').vjs_src(source.src); | 482 | this.el().vjs_src(source.src); |
484 | }); | 483 | }); |
485 | } | 484 | } |
486 | } | 485 | }; |
486 | |||
487 | videojs.Hls.prototype.duration = function() { | ||
488 | var playlists = this.player().hls.playlists; | ||
489 | if (playlists) { | ||
490 | return totalDuration(playlists.media()); | ||
491 | } | ||
492 | return 0; | ||
493 | }; | ||
494 | |||
495 | videojs.Hls.prototype.dispose = function() { | ||
496 | if (this.player().hls.playlists) { | ||
497 | this.player().hls.playlists.dispose(); | ||
498 | } | ||
499 | videojs.Flash.prototype.dispose.call(this); | ||
500 | }; | ||
487 | 501 | ||
488 | //for (var prop in videojs.Flash) { | 502 | //for (var prop in videojs.Flash) { |
489 | //videojs.Hls[prop] = videojs.Flash[prop]; | 503 | //videojs.Hls[prop] = videojs.Flash[prop]; | ... | ... |
... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
15 | <script src="../libs/qunit/qunit.js"></script> | 15 | <script src="../libs/qunit/qunit.js"></script> |
16 | 16 | ||
17 | <!-- video.js --> | 17 | <!-- video.js --> |
18 | <script src="../node_modules/video.js/dist/video-js/video.dev.js"></script> | 18 | <script src="../node_modules/video.js/dist/video-js/video.js"></script> |
19 | <script src="../node_modules/videojs-contrib-media-sources/src/videojs-media-sources.js"></script> | 19 | <script src="../node_modules/videojs-contrib-media-sources/src/videojs-media-sources.js"></script> |
20 | 20 | ||
21 | <!-- HLS plugin --> | 21 | <!-- HLS plugin --> | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment