aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/plyr.js
diff options
context:
space:
mode:
authorSam Potts <me@sampotts.me>2016-02-28 12:50:34 +1100
committerSam Potts <me@sampotts.me>2016-02-28 12:50:34 +1100
commitcd83a2670b322aa03a3659ec554875fa2805b593 (patch)
treeca3ed56dbcc409419f8a1090ddbeae83fc825401 /src/js/plyr.js
parent1bbc47c64f6ad9dfbe58ab05ce65ec6ed9366c4c (diff)
downloadplyr-cd83a2670b322aa03a3659ec554875fa2805b593.tar.lz
plyr-cd83a2670b322aa03a3659ec554875fa2805b593.tar.xz
plyr-cd83a2670b322aa03a3659ec554875fa2805b593.zip
Cancel requests on source change (Fixes #174)
Diffstat (limited to 'src/js/plyr.js')
-rw-r--r--src/js/plyr.js32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js
index 24c6d76d..edac1118 100644
--- a/src/js/plyr.js
+++ b/src/js/plyr.js
@@ -1,6 +1,6 @@
// ==========================================================================
// Plyr
-// plyr.js v1.5.15
+// plyr.js v1.5.16
// https://github.com/selz/plyr
// License: The MIT License (MIT)
// ==========================================================================
@@ -2225,6 +2225,9 @@
_remove(plyr.videoContainer);
}
+ // Cancel current network requests
+ _cancelRequests();
+
// Remove the old media
_remove(plyr.media);
@@ -2521,6 +2524,31 @@
});
}
+ // Cancel current network requests
+ // See https://github.com/Selz/plyr/issues/174
+ function _cancelRequests() {
+ if(!_inArray(config.types.html5, plyr.type)) {
+ return;
+ }
+
+ // Set empty src attribute
+ plyr.media.setAttribute('src', '');
+
+ // Remove child sources
+ var sources = plyr.media.querySelectorAll('source');
+ for (var i = 0; i < sources.length; i++) {
+ _remove(sources[i]);
+ }
+
+ // Load the new empty source
+ // This will cancel existing requests
+ // See https://github.com/Selz/plyr/issues/174
+ plyr.media.load();
+
+ // Debugging
+ _log("Cancelled network requests for old media");
+ }
+
// Destroy an instance
// Event listeners are removed when elements are removed
// http://stackoverflow.com/questions/12528049/if-a-dom-element-is-removed-are-its-listeners-also-removed-from-memory
@@ -2547,7 +2575,7 @@
// If video, we need to remove some more
if (plyr.type === 'video') {
- // Remove captions
+ // Remove captions container
_remove(_getElement(config.selectors.captions));
// Remove video wrapper