Merge pull request #265 from videojs/preload-none
Respect the preload-none option
Showing
4 changed files
with
38 additions
and
5 deletions
... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
7 | <link href="node_modules/video.js/dist/video-js/video-js.css" rel="stylesheet"> | 7 | <link href="node_modules/video.js/dist/video-js/video-js.css" rel="stylesheet"> |
8 | 8 | ||
9 | <!-- video.js --> | 9 | <!-- video.js --> |
10 | <script src="node_modules/video.js/dist/video-js/video.js"></script> | 10 | <script src="node_modules/video.js/dist/video-js/video.dev.js"></script> |
11 | 11 | ||
12 | <!-- Media Sources plugin --> | 12 | <!-- Media Sources plugin --> |
13 | <script src="node_modules/videojs-contrib-media-sources/src/videojs-media-sources.js"></script> | 13 | <script src="node_modules/videojs-contrib-media-sources/src/videojs-media-sources.js"></script> | ... | ... |
... | @@ -45,6 +45,6 @@ | ... | @@ -45,6 +45,6 @@ |
45 | "dependencies": { | 45 | "dependencies": { |
46 | "pkcs7": "^0.2.2", | 46 | "pkcs7": "^0.2.2", |
47 | "videojs-contrib-media-sources": "^1.0.0", | 47 | "videojs-contrib-media-sources": "^1.0.0", |
48 | "videojs-swf": "^4.6.0" | 48 | "videojs-swf": "^4.7.0" |
49 | } | 49 | } |
50 | } | 50 | } | ... | ... |
... | @@ -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,12 @@ videojs.Hls.prototype.fillBuffer = function(offset) { | ... | @@ -558,6 +555,12 @@ 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') && | ||
560 | player.options().preload === 'none') { | ||
561 | return; | ||
562 | } | ||
563 | |||
561 | // if a video has not been specified, do nothing | 564 | // if a video has not been specified, do nothing |
562 | if (!player.currentSrc() || !this.playlists) { | 565 | if (!player.currentSrc() || !this.playlists) { |
563 | return; | 566 | return; | ... | ... |
... | @@ -2299,4 +2299,34 @@ test('live stream should not call endOfStream', function(){ | ... | @@ -2299,4 +2299,34 @@ 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 | tech = player.el().querySelector('.vjs-tech'), | ||
2305 | properties = {}; | ||
2306 | |||
2307 | player.src({ | ||
2308 | src: 'master.m3u8', | ||
2309 | type: 'application/vnd.apple.mpegurl' | ||
2310 | }); | ||
2311 | |||
2312 | tech.vjs_getProperty = function(property) { return properties[property]; }; | ||
2313 | tech.vjs_setProperty = function(property, value) { properties[property] = value; }; | ||
2314 | player.preload('none'); | ||
2315 | |||
2316 | player.hls.loadSegment = function () { | ||
2317 | loadedSegments++; | ||
2318 | }; | ||
2319 | |||
2320 | player.currentSrc = function() { | ||
2321 | return player.src; | ||
2322 | }; | ||
2323 | |||
2324 | openMediaSource(player); | ||
2325 | standardXHRResponse(requests.shift()); // master | ||
2326 | standardXHRResponse(requests.shift()); // media | ||
2327 | player.hls.checkBuffer_(); | ||
2328 | |||
2329 | strictEqual(loadedSegments, 0, 'did not download any segments'); | ||
2330 | }); | ||
2331 | |||
2302 | })(window, window.videojs); | 2332 | })(window, window.videojs); | ... | ... |
-
Please register or sign in to post a comment