aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/captions.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/captions.js')
-rw-r--r--src/js/captions.js35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/js/captions.js b/src/js/captions.js
index 6ab8c69e..c8bc5833 100644
--- a/src/js/captions.js
+++ b/src/js/captions.js
@@ -1,5 +1,6 @@
// ==========================================================================
// Plyr Captions
+// TODO: Create as class
// ==========================================================================
import support from './support';
@@ -45,7 +46,6 @@ const captions = {
return;
}
-
// Inject the container
if (!utils.is.element(this.elements.captions)) {
this.elements.captions = utils.createElement('div', utils.getAttributesFromSelector(this.config.selectors.captions));
@@ -56,11 +56,42 @@ const captions = {
// Set the class hook
utils.toggleClass(this.elements.container, this.config.classNames.captions.enabled, !utils.is.empty(captions.getTracks.call(this)));
+ // Get tracks
+ const tracks = captions.getTracks.call(this);
+
// If no caption file exists, hide container for caption text
- if (utils.is.empty(captions.getTracks.call(this))) {
+ if (utils.is.empty(tracks)) {
return;
}
+ // Get browser info
+ const browser = utils.getBrowser();
+
+ // Fix IE captions if CORS is used
+ // Fetch captions and inject as blobs instead (data URIs not supported!)
+ if (browser.isIE && window.URL) {
+ const elements = this.media.querySelectorAll('track');
+
+ Array.from(elements).forEach(track => {
+ const src = track.getAttribute('src');
+ const href = utils.parseUrl(src);
+
+ if (href.hostname !== window.location.href.hostname && [
+ 'http:',
+ 'https:',
+ ].includes(href.protocol)) {
+ utils
+ .fetch(src, 'blob')
+ .then(blob => {
+ track.setAttribute('src', window.URL.createObjectURL(blob));
+ })
+ .catch(() => {
+ utils.removeElement(track);
+ });
+ }
+ });
+ }
+
// Set language
captions.setLanguage.call(this);