ae1590c7 by Brandon Bay Committed by David LaPalomento

Respect the preload-none option

Don’t start downloading segments if preload is set to “none”
1 parent 5c4a7c05
...@@ -143,9 +143,6 @@ videojs.Hls.prototype.src = function(src) { ...@@ -143,9 +143,6 @@ videojs.Hls.prototype.src = function(src) {
143 143
144 setupEvents = function() { 144 setupEvents = function() {
145 this.fillBuffer(); 145 this.fillBuffer();
146
147
148
149 player.trigger('loadedmetadata'); 146 player.trigger('loadedmetadata');
150 }; 147 };
151 148
...@@ -558,6 +555,11 @@ videojs.Hls.prototype.fillBuffer = function(offset) { ...@@ -558,6 +555,11 @@ videojs.Hls.prototype.fillBuffer = function(offset) {
558 segment, 555 segment,
559 segmentUri; 556 segmentUri;
560 557
558 // if preload is set to "none", do not download segments until playback is requested
559 if (!player.hasClass('vjs-has-started') && player.options.preload === "none") {
560 return;
561 }
562
561 // if a video has not been specified, do nothing 563 // if a video has not been specified, do nothing
562 if (!player.currentSrc() || !this.playlists) { 564 if (!player.currentSrc() || !this.playlists) {
563 return; 565 return;
......
...@@ -2299,4 +2299,29 @@ test('live stream should not call endOfStream', function(){ ...@@ -2299,4 +2299,29 @@ test('live stream should not call endOfStream', function(){
2299 "media source should be in open state, not ended state for live stream after the last segment in m3u8 downloaded"); 2299 "media source should be in open state, not ended state for live stream after the last segment in m3u8 downloaded");
2300 }); 2300 });
2301 2301
2302 test('does not download segments if preload option set to none', function() {
2303 var loadedSegments = 0;
2304 player.src({
2305 src: 'master.m3u8',
2306 type: 'application/vnd.apple.mpegurl'
2307 });
2308
2309 player.options.preload = "none";
2310
2311 player.hls.loadSegment = function () {
2312 loadedSegments++;
2313 };
2314
2315 player.currentSrc = function() {
2316 return player.src;
2317 };
2318
2319 openMediaSource(player);
2320 standardXHRResponse(requests.shift()); // master
2321 standardXHRResponse(requests.shift()); // media
2322 player.hls.checkBuffer_();
2323
2324 strictEqual(loadedSegments, 0, 'did not download any segments');
2325 });
2326
2302 })(window, window.videojs); 2327 })(window, window.videojs);
......