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
} else {
player.duration(totalDuration(parser.manifest));
}
// periodicaly check if the buffer needs to be refilled
player.on('timeupdate', fillBuffer);
player.trigger('loadedmanifest');
player.trigger('loadedmetadata');
fillBuffer();
return;
}
......@@ -536,9 +541,6 @@ var
player.hls.sourceBuffer = sourceBuffer;
sourceBuffer.appendBuffer(segmentParser.getFlvHeader());
player.on('loadedmetadata', fillBuffer);
player.on('timeupdate', fillBuffer);
player.hls.mediaIndex = 0;
downloadPlaylist(srcUrl);
});
......
......@@ -239,6 +239,24 @@ test('downloads media playlists after loading the master', function() {
'first segment requested');
});
test('timeupdates do not check to fill the buffer until a media playlist is ready', function() {
var urls = [];
window.XMLHttpRequest = function() {
this.open = function(method, url) {
urls.push(url);
};
this.send = function() {};
};
player.hls('manifest/media.m3u8');
videojs.mediaSources[player.currentSrc()].trigger({
type: 'sourceopen'
});
player.trigger('timeupdate');
strictEqual(1, urls.length, 'one request was made');
strictEqual('manifest/media.m3u8', urls[0], 'media playlist requested');
});
test('calculates the bandwidth after downloading a segment', function() {
player.hls('manifest/media.m3u8');
videojs.mediaSources[player.currentSrc()].trigger({
......