Merge pull request #177 from videojs/cancelXhrs
Cancel xhrs
Showing
1 changed file
with
19 additions
and
15 deletions
... | @@ -138,8 +138,7 @@ videojs.Hls.prototype.handleSourceOpen = function() { | ... | @@ -138,8 +138,7 @@ videojs.Hls.prototype.handleSourceOpen = function() { |
138 | this.playlists.on('mediachange', videojs.bind(this, function() { | 138 | this.playlists.on('mediachange', videojs.bind(this, function() { |
139 | // abort outstanding key requests and check if new keys need to be retrieved | 139 | // abort outstanding key requests and check if new keys need to be retrieved |
140 | if (keyXhr) { | 140 | if (keyXhr) { |
141 | keyXhr.abort(); | 141 | this.cancelKeyXhr(); |
142 | keyXhr = null; | ||
143 | this.fetchKeys(this.playlists.media(), this.mediaIndex); | 142 | this.fetchKeys(this.playlists.media(), this.mediaIndex); |
144 | } | 143 | } |
145 | 144 | ||
... | @@ -195,17 +194,12 @@ videojs.Hls.prototype.setCurrentTime = function(currentTime) { | ... | @@ -195,17 +194,12 @@ videojs.Hls.prototype.setCurrentTime = function(currentTime) { |
195 | this.sourceBuffer.abort(); | 194 | this.sourceBuffer.abort(); |
196 | 195 | ||
197 | // cancel outstanding requests and buffer appends | 196 | // cancel outstanding requests and buffer appends |
198 | if (this.segmentXhr_) { | 197 | this.cancelSegmentXhr(); |
199 | this.segmentXhr_.onreadystatechange = null; | ||
200 | this.segmentXhr_.abort(); | ||
201 | this.segmentXhr_ = null; | ||
202 | } | ||
203 | 198 | ||
204 | // fetch new encryption keys, if necessary | 199 | // fetch new encryption keys, if necessary |
205 | if (keyXhr) { | 200 | if (keyXhr) { |
206 | keyXhr.aborted = true; | 201 | keyXhr.aborted = true; |
207 | keyXhr.abort(); | 202 | this.cancelKeyXhr(); |
208 | keyXhr = null; | ||
209 | this.fetchKeys(this.playlists.media(), this.mediaIndex); | 203 | this.fetchKeys(this.playlists.media(), this.mediaIndex); |
210 | } | 204 | } |
211 | 205 | ||
... | @@ -244,18 +238,28 @@ videojs.Hls.prototype.updateDuration = function(playlist) { | ... | @@ -244,18 +238,28 @@ videojs.Hls.prototype.updateDuration = function(playlist) { |
244 | * state suitable for switching to a different video. | 238 | * state suitable for switching to a different video. |
245 | */ | 239 | */ |
246 | videojs.Hls.prototype.resetSrc_ = function() { | 240 | videojs.Hls.prototype.resetSrc_ = function() { |
247 | if (this.segmentXhr_) { | 241 | this.cancelSegmentXhr(); |
248 | this.segmentXhr_.onreadystatechange = null; | 242 | this.cancelKeyXhr(); |
249 | this.segmentXhr_.abort(); | 243 | |
250 | this.segmentXhr_ = null; | 244 | if (this.sourceBuffer) { |
245 | this.sourceBuffer.abort(); | ||
251 | } | 246 | } |
247 | }; | ||
248 | |||
249 | videojs.Hls.prototype.cancelKeyXhr = function() { | ||
252 | if (keyXhr) { | 250 | if (keyXhr) { |
253 | keyXhr.onreadystatechange = null; | 251 | keyXhr.onreadystatechange = null; |
254 | keyXhr.abort(); | 252 | keyXhr.abort(); |
255 | keyXhr = null; | 253 | keyXhr = null; |
256 | } | 254 | } |
257 | if (this.sourceBuffer) { | 255 | }; |
258 | this.sourceBuffer.abort(); | 256 | |
257 | videojs.Hls.prototype.cancelSegmentXhr = function() { | ||
258 | if (this.segmentXhr_) { | ||
259 | // Prevent error handler from running. | ||
260 | this.segmentXhr_.onreadystatechange = null; | ||
261 | this.segmentXhr_.abort(); | ||
262 | this.segmentXhr_ = null; | ||
259 | } | 263 | } |
260 | }; | 264 | }; |
261 | 265 | ... | ... |
-
Please register or sign in to post a comment