Merge pull request #38 from videojs/basic-live
Flash Tech Fix for Live UI
Showing
3 changed files
with
55 additions
and
12 deletions
... | @@ -204,13 +204,8 @@ var | ... | @@ -204,13 +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.segments) { | ||
211 | return 0; | ||
212 | } | ||
213 | i = playlist.segments.length; | ||
214 | 209 | ||
215 | // if present, use the duration specified in the playlist | 210 | // if present, use the duration specified in the playlist |
216 | if (playlist.totalDuration) { | 211 | if (playlist.totalDuration) { |
... | @@ -292,7 +287,8 @@ var | ... | @@ -292,7 +287,8 @@ var |
292 | segmentXhr, | 287 | segmentXhr, |
293 | loadedPlaylist, | 288 | loadedPlaylist, |
294 | fillBuffer, | 289 | fillBuffer, |
295 | updateCurrentPlaylist; | 290 | updateCurrentPlaylist, |
291 | updateDuration; | ||
296 | 292 | ||
297 | // if the video element supports HLS natively, do nothing | 293 | // if the video element supports HLS natively, do nothing |
298 | if (videojs.hls.supportsNativeHls) { | 294 | if (videojs.hls.supportsNativeHls) { |
... | @@ -381,6 +377,22 @@ var | ... | @@ -381,6 +377,22 @@ var |
381 | }); | 377 | }); |
382 | 378 | ||
383 | /** | 379 | /** |
380 | * Update the player duration | ||
381 | */ | ||
382 | updateDuration = function(playlist) { | ||
383 | var tech; | ||
384 | // update the duration | ||
385 | player.duration(totalDuration(playlist)); | ||
386 | // tell the flash tech of the new duration | ||
387 | tech = player.el().querySelector('.vjs-tech'); | ||
388 | if(tech.vjs_setProperty) { | ||
389 | tech.vjs_setProperty('duration', player.duration()); | ||
390 | } | ||
391 | // manually fire the duration change | ||
392 | player.trigger('durationchange'); | ||
393 | }; | ||
394 | |||
395 | /** | ||
384 | * Determine whether the current media playlist should be changed | 396 | * Determine whether the current media playlist should be changed |
385 | * and trigger a switch if necessary. If a sufficiently fresh | 397 | * and trigger a switch if necessary. If a sufficiently fresh |
386 | * version of the target playlist is available, the switch will take | 398 | * version of the target playlist is available, the switch will take |
... | @@ -406,8 +418,7 @@ var | ... | @@ -406,8 +418,7 @@ var |
406 | playlist); | 418 | playlist); |
407 | player.hls.media = playlist; | 419 | player.hls.media = playlist; |
408 | 420 | ||
409 | // update the duration | 421 | updateDuration(player.hls.media); |
410 | player.duration(totalDuration(player.hls.media)); | ||
411 | } | 422 | } |
412 | }; | 423 | }; |
413 | 424 | ||
... | @@ -558,7 +569,7 @@ var | ... | @@ -558,7 +569,7 @@ var |
558 | player.hls.media = player.hls.master.playlists[0]; | 569 | player.hls.media = player.hls.master.playlists[0]; |
559 | 570 | ||
560 | // update the duration | 571 | // update the duration |
561 | player.duration(totalDuration(parser.manifest)); | 572 | updateDuration(parser.manifest); |
562 | 573 | ||
563 | // periodicaly check if the buffer needs to be refilled | 574 | // periodicaly check if the buffer needs to be refilled |
564 | player.on('timeupdate', fillBuffer); | 575 | player.on('timeupdate', fillBuffer); |
... | @@ -585,7 +596,7 @@ var | ... | @@ -585,7 +596,7 @@ var |
585 | var | 596 | var |
586 | buffered = player.buffered(), | 597 | buffered = player.buffered(), |
587 | bufferedTime = 0, | 598 | bufferedTime = 0, |
588 | segment = player.hls.media.segments[player.hls.mediaIndex], | 599 | segment, |
589 | segmentUri, | 600 | segmentUri, |
590 | startTime; | 601 | startTime; |
591 | 602 | ||
... | @@ -594,7 +605,13 @@ var | ... | @@ -594,7 +605,13 @@ var |
594 | return; | 605 | return; |
595 | } | 606 | } |
596 | 607 | ||
608 | // if no segments are available, do nothing | ||
609 | if (!player.hls.media.segments) { | ||
610 | return; | ||
611 | } | ||
612 | |||
597 | // 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]; | ||
598 | if (!segment) { | 615 | if (!segment) { |
599 | return; | 616 | return; |
600 | } | 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