7e8d631e by David LaPalomento

Don't register fillBuffer checks until after a media playlist has downloaded

Fixes #110. Fixes #116. If timeupdates were being firing without a media playlist available yet, fillBuffer would dereference a property on undefined and blow up. Timeupdates occur manually on a fixed interval when using the Flash tech so this was guaranteed to happen whenever the media playlist was unretrievable. To avoid this, wait to register buffer checks until a media playlist has been successfully downloaded. As it turns out, this is the same moment we normally trigger loadedmetadata so it was possible to transform a loadedmetadata handler into a direct call to fillBuffer.
1 parent da03d91d
...@@ -394,8 +394,13 @@ var ...@@ -394,8 +394,13 @@ var
394 } else { 394 } else {
395 player.duration(totalDuration(parser.manifest)); 395 player.duration(totalDuration(parser.manifest));
396 } 396 }
397
398 // periodicaly check if the buffer needs to be refilled
399 player.on('timeupdate', fillBuffer);
400
397 player.trigger('loadedmanifest'); 401 player.trigger('loadedmanifest');
398 player.trigger('loadedmetadata'); 402 player.trigger('loadedmetadata');
403 fillBuffer();
399 return; 404 return;
400 } 405 }
401 406
...@@ -536,9 +541,6 @@ var ...@@ -536,9 +541,6 @@ var
536 player.hls.sourceBuffer = sourceBuffer; 541 player.hls.sourceBuffer = sourceBuffer;
537 sourceBuffer.appendBuffer(segmentParser.getFlvHeader()); 542 sourceBuffer.appendBuffer(segmentParser.getFlvHeader());
538 543
539 player.on('loadedmetadata', fillBuffer);
540 player.on('timeupdate', fillBuffer);
541
542 player.hls.mediaIndex = 0; 544 player.hls.mediaIndex = 0;
543 downloadPlaylist(srcUrl); 545 downloadPlaylist(srcUrl);
544 }); 546 });
......
...@@ -239,6 +239,24 @@ test('downloads media playlists after loading the master', function() { ...@@ -239,6 +239,24 @@ test('downloads media playlists after loading the master', function() {
239 'first segment requested'); 239 'first segment requested');
240 }); 240 });
241 241
242 test('timeupdates do not check to fill the buffer until a media playlist is ready', function() {
243 var urls = [];
244 window.XMLHttpRequest = function() {
245 this.open = function(method, url) {
246 urls.push(url);
247 };
248 this.send = function() {};
249 };
250 player.hls('manifest/media.m3u8');
251 videojs.mediaSources[player.currentSrc()].trigger({
252 type: 'sourceopen'
253 });
254 player.trigger('timeupdate');
255
256 strictEqual(1, urls.length, 'one request was made');
257 strictEqual('manifest/media.m3u8', urls[0], 'media playlist requested');
258 });
259
242 test('calculates the bandwidth after downloading a segment', function() { 260 test('calculates the bandwidth after downloading a segment', function() {
243 player.hls('manifest/media.m3u8'); 261 player.hls('manifest/media.m3u8');
244 videojs.mediaSources[player.currentSrc()].trigger({ 262 videojs.mediaSources[player.currentSrc()].trigger({
......