merge fix, add test
Showing
2 changed files
with
35 additions
and
10 deletions
... | @@ -204,14 +204,8 @@ var | ... | @@ -204,14 +204,8 @@ var |
204 | totalDuration = function(playlist) { | 204 | totalDuration = function(playlist) { |
205 | var | 205 | var |
206 | duration = 0, | 206 | duration = 0, |
207 | i, | 207 | segment, |
208 | segment; | 208 | i = (playlist.segments || []).length; |
209 | |||
210 | if (!playlist || !playlist.segments) { | ||
211 | return 0; | ||
212 | } | ||
213 | |||
214 | i = playlist.segments.length; | ||
215 | 209 | ||
216 | // if present, use the duration specified in the playlist | 210 | // if present, use the duration specified in the playlist |
217 | if (playlist.totalDuration) { | 211 | if (playlist.totalDuration) { |
... | @@ -386,10 +380,11 @@ var | ... | @@ -386,10 +380,11 @@ var |
386 | * Update the player duration | 380 | * Update the player duration |
387 | */ | 381 | */ |
388 | updateDuration = function(playlist) { | 382 | updateDuration = function(playlist) { |
383 | var tech; | ||
389 | // update the duration | 384 | // update the duration |
390 | player.duration(totalDuration(playlist)); | 385 | player.duration(totalDuration(playlist)); |
391 | // tell the flash tech of the new duration | 386 | // tell the flash tech of the new duration |
392 | var tech = player.el().querySelector('.vjs-tech'); | 387 | tech = player.el().querySelector('.vjs-tech'); |
393 | if(tech.vjs_setProperty) { | 388 | if(tech.vjs_setProperty) { |
394 | tech.vjs_setProperty('duration', player.duration()); | 389 | tech.vjs_setProperty('duration', player.duration()); |
395 | } | 390 | } |
... | @@ -601,7 +596,7 @@ var | ... | @@ -601,7 +596,7 @@ var |
601 | var | 596 | var |
602 | buffered = player.buffered(), | 597 | buffered = player.buffered(), |
603 | bufferedTime = 0, | 598 | bufferedTime = 0, |
604 | segment = player.hls.media.segments[player.hls.mediaIndex], | 599 | segment, |
605 | segmentUri, | 600 | segmentUri, |
606 | startTime; | 601 | startTime; |
607 | 602 | ||
... | @@ -610,7 +605,13 @@ var | ... | @@ -610,7 +605,13 @@ var |
610 | return; | 605 | return; |
611 | } | 606 | } |
612 | 607 | ||
608 | // if no segments are available, do nothing | ||
609 | if (!player.hls.media.segments) { | ||
610 | return; | ||
611 | } | ||
612 | |||
613 | // if the video has finished downloading, stop trying to buffer | 613 | // if the video has finished downloading, stop trying to buffer |
614 | segment = player.hls.media.segments[player.hls.mediaIndex]; | ||
614 | if (!segment) { | 615 | if (!segment) { |
615 | return; | 616 | return; |
616 | } | 617 | } | ... | ... |
... | @@ -1109,4 +1109,28 @@ test('only reloads the active media playlist', function() { | ... | @@ -1109,4 +1109,28 @@ test('only reloads the active media playlist', function() { |
1109 | 'refreshed the active playlist'); | 1109 | 'refreshed the active playlist'); |
1110 | }); | 1110 | }); |
1111 | 1111 | ||
1112 | test('does not break if the playlist has no segments', function() { | ||
1113 | window.XMLHttpRequest = function () { | ||
1114 | this.open = function () {}; | ||
1115 | this.send = function () { | ||
1116 | this.readyState = 4; | ||
1117 | this.status = 200; | ||
1118 | this.responseText = '#EXTM3U\n' + | ||
1119 | '#EXT-X-PLAYLIST-TYPE:VOD\n' + | ||
1120 | '#EXT-X-TARGETDURATION:10\n'; | ||
1121 | this.onreadystatechange(); | ||
1122 | }; | ||
1123 | }; | ||
1124 | player.hls('manifest/master.m3u8'); | ||
1125 | try { | ||
1126 | videojs.mediaSources[player.currentSrc()].trigger({ | ||
1127 | type: 'sourceopen' | ||
1128 | }); | ||
1129 | } catch(e) { | ||
1130 | ok(false, 'an error was thrown'); | ||
1131 | throw e; | ||
1132 | } | ||
1133 | ok(true, 'no error was thrown'); | ||
1134 | }); | ||
1135 | |||
1112 | })(window, window.videojs); | 1136 | })(window, window.videojs); | ... | ... |
-
Please register or sign in to post a comment