From 6537225c61c08d97617172e1ab8347f6048ed533 Mon Sep 17 00:00:00 2001 From: Chrysa Papadopoulou Date: Fri, 24 Feb 2017 16:32:17 +0200 Subject: Subtitles tracks --- src/js/plyr.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/js/plyr.js b/src/js/plyr.js index 88fcd548..0a303d83 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -84,6 +84,8 @@ forward: '[data-plyr="fast-forward"]', mute: '[data-plyr="mute"]', captions: '[data-plyr="captions"]', + captions_menu: '[data-plyr="captions_menu"]', + captions_lang: '[data-plyr="captions_lang"]', fullscreen: '[data-plyr="fullscreen"]', settings: '[data-plyr="settings"]', pip: '[data-plyr="pip"]', @@ -200,6 +202,7 @@ mute: null, volume: null, captions: null, + captions_lang: null, fullscreen: null, speed: null, loop: null @@ -814,6 +817,19 @@ }; } + function buildCaptionsMenu() { + var trackSubs = ''; + if (Array.isArray(config.tracks) && config.tracks.length > 0) { + for (var i in config.tracks) { + var track = config.tracks[i]; + if (typeof track == 'function') continue; + trackSubs += ''; + } + } + + return trackSubs; + } + // Build the default HTML function buildControls() { // Create html array @@ -978,6 +994,16 @@ // Settings button / menu if (inArray(config.controls, 'settings')) { /* beautify ignore:start */ + var captionsMenuItem = ''; + if (inArray(config.controls, 'captions')) { + captionsMenuItem = '
  • '+ + ''+ + '
  • '; + } + html.push( '
    ', '', - '', + captionsMenuItem, '
  • ', '', '
  • ', - '
  • ', - '', + '
  • ', + buildCaptionsMenu(), '
  • ', '
  • ', - '', + '', '
  • ', '', '
    ', @@ -1763,12 +1784,14 @@ settings: getElement(config.selectors.buttons.settings), pip: getElement(config.selectors.buttons.pip), speed: document.querySelectorAll(config.selectors.buttons.speed), - loop: document.querySelectorAll(config.selectors.buttons.loop) + loop: document.querySelectorAll(config.selectors.buttons.loop), + captions_lang: getElements(config.selectors.buttons.captions_lang) }; // Inputs plyr.buttons.mute = getElement(config.selectors.buttons.mute); plyr.buttons.captions = getElement(config.selectors.buttons.captions); + plyr.buttons.captions_menu = getElement(config.selectors.buttons.captions_menu); // Progress plyr.progress = { @@ -2881,6 +2904,8 @@ // Set global plyr.captionsEnabled = show; + plyr.buttons.captions_menu.innerHTML = show ? 'Off' : 'On'; + getElement('[data-captions="settings"]').innerHTML = getSubsLangValue(); // Toggle state toggleState(plyr.buttons.captions, plyr.captionsEnabled); @@ -2900,13 +2925,27 @@ // Select active caption function setCaptionIndex(index) { // Save active caption - config.captions.selectedIndex = index; + config.captions.selectedIndex = index || config.captions.selectedIndex; // Clear caption setCaption(); // Re-run setup setupCaptions(); + + getElement('[data-captions="settings"]').innerHTML = getSubsLangValue(); + } + + function getSubsLangValue() { + if (config.tracks.length === 0) { + return 'No Subs'; + } + + if (plyr.captionsEnabled || !is.boolean(plyr.captionsEnabled) && plyr.storage.captionsEnabled) { + return config.tracks[config.captions.selectedIndex].label; + } else { + return 'Disabled'; + } } // Check if media is loading @@ -3688,6 +3727,12 @@ // Captions on(plyr.buttons.captions, 'click', toggleCaptions); + on(plyr.buttons.captions_menu, 'click', toggleCaptions); + // Captions language + proxy(plyr.buttons.captions_lang, 'click', config.listeners.captions_lang, function(e) { + var langIndex = e.target.attributes.getNamedItem("data-index").value; + setCaptionIndex(langIndex); + }); // Settings on(plyr.buttons.settings, 'click', function(event) { @@ -4115,6 +4160,7 @@ // Captions setupCaptions(); + setCaptionIndex(); // Set volume setVolume(); -- cgit v1.2.3 From 9919d8078249c95b7c2c5a186f2dd783e7c96611 Mon Sep 17 00:00:00 2001 From: Marios Tasos Date: Wed, 15 Mar 2017 17:18:34 +0200 Subject: check if captions exists --- src/js/plyr.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/js/plyr.js b/src/js/plyr.js index 117eb70d..2b664fc0 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -1517,27 +1517,30 @@ function setCaption(caption) { var captions = getElement(config.selectors.captions); var content = document.createElement('span'); + if(captions) { - // Empty the container - captions.innerHTML = ''; + // Empty the container + captions.innerHTML = ''; - // Default to empty - if (is.undefined(caption)) { + // Default to empty + if (is.undefined(caption)) { caption = ''; - } + } - // Set the span content - if (is.string(caption)) { + // Set the span content + if (is.string(caption)) { content.innerHTML = caption.trim(); - } else { + } else { content.appendChild(caption); - } + } + + // Set new caption text + captions.appendChild(content); - // Set new caption text - captions.appendChild(content); + // Force redraw (for Safari) + var redraw = captions.offsetHeight; + } - // Force redraw (for Safari) - var redraw = captions.offsetHeight; } // Captions functions -- cgit v1.2.3 From 9c867edfbc4ee8da3a42b71d37bf9e407707433a Mon Sep 17 00:00:00 2001 From: Marios Tasos Date: Sat, 18 Mar 2017 01:59:20 +0200 Subject: fix data typo in language button --- src/js/plyr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/js/plyr.js b/src/js/plyr.js index 2b664fc0..25ea6ab9 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -827,7 +827,7 @@ for (var i in config.tracks) { var track = config.tracks[i]; if (typeof track == 'function') continue; - trackSubs += ''; + trackSubs += ''; } } -- cgit v1.2.3 From c205c47509bced7ddeaca213f8ea7bae5224d5a1 Mon Sep 17 00:00:00 2001 From: Marios Tasos Date: Wed, 22 Mar 2017 13:38:08 +0200 Subject: set captionExists to true if selectedIndex is bigger than capt source --- src/js/plyr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/js/plyr.js b/src/js/plyr.js index 25ea6ab9..a9a9d90c 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -1401,7 +1401,7 @@ plyr.captionExists = false; log('No caption track found'); } else if ((config.captions.selectedIndex + 1) > captionSources.length) { - plyr.captionExists = false; + plyr.captionExists = true; log('Caption index out of bound'); } else { captionSrc = captionSources[config.captions.selectedIndex]; -- cgit v1.2.3 From a353194fe193f19b7b92bbd1b936d6b6cd311b6b Mon Sep 17 00:00:00 2001 From: Marios Tasos Date: Wed, 22 Mar 2017 15:50:56 +0200 Subject: make config.captions.selectedIndex number --- src/js/plyr.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/js/plyr.js b/src/js/plyr.js index a9a9d90c..b7c13474 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -1400,8 +1400,8 @@ if (captionSources.length === 0) { plyr.captionExists = false; log('No caption track found'); - } else if ((config.captions.selectedIndex + 1) > captionSources.length) { - plyr.captionExists = true; + } else if ((Number(config.captions.selectedIndex) + 1) > captionSources.length) { + plyr.captionExists = false; log('Caption index out of bound'); } else { captionSrc = captionSources[config.captions.selectedIndex]; -- cgit v1.2.3 From 9ba3753f808a69a1da98de161d3cfbce57235354 Mon Sep 17 00:00:00 2001 From: Marios Tasos Date: Fri, 24 Mar 2017 17:25:09 +0200 Subject: toggle quality options --- src/js/plyr.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/js/plyr.js b/src/js/plyr.js index b7c13474..14b45fd9 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -57,6 +57,7 @@ hideControls: true, showPosterOnEnd: false, disableContextMenu: true, + qualityOptions: false, keyboardShorcuts: { focused: true, global: false @@ -1008,6 +1009,13 @@ ''; } + if(config.qualityOptions){ + var showQuality = ''; + showQuality = ''; + } + html.push( '
    ', '', '', '
  • ', - '', + showQuality, + // '', '
  • ', '
  • ', ''; + ''; } html.push( @@ -1035,10 +1034,6 @@ '
  • ', '
  • ', showQuality, - // '', '
  • ', '
  • ', '