11157fa5 by David LaPalomento

Merge pull request #265 from videojs/preload-none

Respect the preload-none option
2 parents 5c4a7c05 bca4ff16
......@@ -5,9 +5,9 @@
<title>video.js HLS Plugin Example</title>
<link href="node_modules/video.js/dist/video-js/video-js.css" rel="stylesheet">
<!-- video.js -->
<script src="node_modules/video.js/dist/video-js/video.js"></script>
<script src="node_modules/video.js/dist/video-js/video.dev.js"></script>
<!-- Media Sources plugin -->
<script src="node_modules/videojs-contrib-media-sources/src/videojs-media-sources.js"></script>
......
......@@ -45,6 +45,6 @@
"dependencies": {
"pkcs7": "^0.2.2",
"videojs-contrib-media-sources": "^1.0.0",
"videojs-swf": "^4.6.0"
"videojs-swf": "^4.7.0"
}
}
......
......@@ -143,9 +143,6 @@ videojs.Hls.prototype.src = function(src) {
setupEvents = function() {
this.fillBuffer();
player.trigger('loadedmetadata');
};
......@@ -558,6 +555,12 @@ videojs.Hls.prototype.fillBuffer = function(offset) {
segment,
segmentUri;
// if preload is set to "none", do not download segments until playback is requested
if (!player.hasClass('vjs-has-started') &&
player.options().preload === 'none') {
return;
}
// if a video has not been specified, do nothing
if (!player.currentSrc() || !this.playlists) {
return;
......
......@@ -2299,4 +2299,34 @@ test('live stream should not call endOfStream', function(){
"media source should be in open state, not ended state for live stream after the last segment in m3u8 downloaded");
});
test('does not download segments if preload option set to none', function() {
var loadedSegments = 0,
tech = player.el().querySelector('.vjs-tech'),
properties = {};
player.src({
src: 'master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
tech.vjs_getProperty = function(property) { return properties[property]; };
tech.vjs_setProperty = function(property, value) { properties[property] = value; };
player.preload('none');
player.hls.loadSegment = function () {
loadedSegments++;
};
player.currentSrc = function() {
return player.src;
};
openMediaSource(player);
standardXHRResponse(requests.shift()); // master
standardXHRResponse(requests.shift()); // media
player.hls.checkBuffer_();
strictEqual(loadedSegments, 0, 'did not download any segments');
});
})(window, window.videojs);
......