348ef762 by Gary Katsevman

Merge branch 'master' into withcredentials

2 parents e25f8997 7a9c64e1
1 .DS_Store
2 dist/*
1 /node_modules/ 3 /node_modules/
2 *~ 4 *~
3 *.iml 5 *.iml
......
...@@ -7,7 +7,10 @@ notifications: ...@@ -7,7 +7,10 @@ notifications:
7 hipchat: 7 hipchat:
8 rooms: 8 rooms:
9 secure: l5TTd5JuPAW883PtcyaIBcJI9Chr9JpsZPQAEUBKAgIEwzuS6y7t5arlkS1PwH6gi1FADzYDf+OXSIou4GkTSrIetnBcT/SAgF0gBKgIhj+eRkuCfZ4VaC7BPhfZ0hgYRE+5Ejf5BM2MJafRm0pj7OlqG4xKrQZwtuV1te5r3JY= 9 secure: l5TTd5JuPAW883PtcyaIBcJI9Chr9JpsZPQAEUBKAgIEwzuS6y7t5arlkS1PwH6gi1FADzYDf+OXSIou4GkTSrIetnBcT/SAgF0gBKgIhj+eRkuCfZ4VaC7BPhfZ0hgYRE+5Ejf5BM2MJafRm0pj7OlqG4xKrQZwtuV1te5r3JY=
10 irc: chat.freenode.net#videojs 10 irc:
11 channels:
12 - "chat.freenode.net#videojs"
13 use_notice: true
11 #addons: 14 #addons:
12 #sauce_connect: 15 #sauce_connect:
13 #username: 16 #username:
......
...@@ -223,13 +223,8 @@ var ...@@ -223,13 +223,8 @@ var
223 totalDuration = function(playlist) { 223 totalDuration = function(playlist) {
224 var 224 var
225 duration = 0, 225 duration = 0,
226 i, 226 segment,
227 segment; 227 i = (playlist.segments || []).length;
228
229 if (!playlist.segments) {
230 return 0;
231 }
232 i = playlist.segments.length;
233 228
234 // if present, use the duration specified in the playlist 229 // if present, use the duration specified in the playlist
235 if (playlist.totalDuration) { 230 if (playlist.totalDuration) {
...@@ -311,7 +306,8 @@ var ...@@ -311,7 +306,8 @@ var
311 segmentXhr, 306 segmentXhr,
312 loadedPlaylist, 307 loadedPlaylist,
313 fillBuffer, 308 fillBuffer,
314 updateCurrentPlaylist; 309 updateCurrentPlaylist,
310 updateDuration;
315 311
316 // if the video element supports HLS natively, do nothing 312 // if the video element supports HLS natively, do nothing
317 if (videojs.hls.supportsNativeHls) { 313 if (videojs.hls.supportsNativeHls) {
...@@ -402,6 +398,22 @@ var ...@@ -402,6 +398,22 @@ var
402 }); 398 });
403 399
404 /** 400 /**
401 * Update the player duration
402 */
403 updateDuration = function(playlist) {
404 var tech;
405 // update the duration
406 player.duration(totalDuration(playlist));
407 // tell the flash tech of the new duration
408 tech = player.el().querySelector('.vjs-tech');
409 if(tech.vjs_setProperty) {
410 tech.vjs_setProperty('duration', player.duration());
411 }
412 // manually fire the duration change
413 player.trigger('durationchange');
414 };
415
416 /**
405 * Determine whether the current media playlist should be changed 417 * Determine whether the current media playlist should be changed
406 * and trigger a switch if necessary. If a sufficiently fresh 418 * and trigger a switch if necessary. If a sufficiently fresh
407 * version of the target playlist is available, the switch will take 419 * version of the target playlist is available, the switch will take
...@@ -427,8 +439,7 @@ var ...@@ -427,8 +439,7 @@ var
427 playlist); 439 playlist);
428 player.hls.media = playlist; 440 player.hls.media = playlist;
429 441
430 // update the duration 442 updateDuration(player.hls.media);
431 player.duration(totalDuration(player.hls.media));
432 } 443 }
433 }; 444 };
434 445
...@@ -579,7 +590,7 @@ var ...@@ -579,7 +590,7 @@ var
579 player.hls.media = player.hls.master.playlists[0]; 590 player.hls.media = player.hls.master.playlists[0];
580 591
581 // update the duration 592 // update the duration
582 player.duration(totalDuration(parser.manifest)); 593 updateDuration(parser.manifest);
583 594
584 // periodicaly check if the buffer needs to be refilled 595 // periodicaly check if the buffer needs to be refilled
585 player.on('timeupdate', fillBuffer); 596 player.on('timeupdate', fillBuffer);
...@@ -606,7 +617,7 @@ var ...@@ -606,7 +617,7 @@ var
606 var 617 var
607 buffered = player.buffered(), 618 buffered = player.buffered(),
608 bufferedTime = 0, 619 bufferedTime = 0,
609 segment = player.hls.media.segments[player.hls.mediaIndex], 620 segment,
610 segmentUri, 621 segmentUri,
611 startTime; 622 startTime;
612 623
...@@ -615,7 +626,13 @@ var ...@@ -615,7 +626,13 @@ var
615 return; 626 return;
616 } 627 }
617 628
629 // if no segments are available, do nothing
630 if (!player.hls.media.segments) {
631 return;
632 }
633
618 // if the video has finished downloading, stop trying to buffer 634 // if the video has finished downloading, stop trying to buffer
635 segment = player.hls.media.segments[player.hls.mediaIndex];
619 if (!segment) { 636 if (!segment) {
620 return; 637 return;
621 } 638 }
......
...@@ -1171,4 +1171,28 @@ test('if withCredentials option is used, withCredentials is set on the XHR objec ...@@ -1171,4 +1171,28 @@ test('if withCredentials option is used, withCredentials is set on the XHR objec
1171 ok(requests[0].withCredentials, "with credentials should be set to true if that option is passed in"); 1171 ok(requests[0].withCredentials, "with credentials should be set to true if that option is passed in");
1172 }); 1172 });
1173 1173
1174 test('does not break if the playlist has no segments', function() {
1175 window.XMLHttpRequest = function () {
1176 this.open = function () {};
1177 this.send = function () {
1178 this.readyState = 4;
1179 this.status = 200;
1180 this.responseText = '#EXTM3U\n' +
1181 '#EXT-X-PLAYLIST-TYPE:VOD\n' +
1182 '#EXT-X-TARGETDURATION:10\n';
1183 this.onreadystatechange();
1184 };
1185 };
1186 player.hls('manifest/master.m3u8');
1187 try {
1188 videojs.mediaSources[player.currentSrc()].trigger({
1189 type: 'sourceopen'
1190 });
1191 } catch(e) {
1192 ok(false, 'an error was thrown');
1193 throw e;
1194 }
1195 ok(true, 'no error was thrown');
1196 });
1197
1174 })(window, window.videojs); 1198 })(window, window.videojs);
......