From 61f4b998e1b9909b30a676463d7afa696299662e Mon Sep 17 00:00:00 2001 From: Philip Giuliani Date: Thu, 31 May 2018 10:17:21 +0200 Subject: Wait for the metadata to be loaded before setting the currentTime --- src/js/html5.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/js/html5.js') diff --git a/src/js/html5.js b/src/js/html5.js index 3818a441..63596cfc 100644 --- a/src/js/html5.js +++ b/src/js/html5.js @@ -99,6 +99,13 @@ const html5 = { // Set new source player.media.src = supported[0].getAttribute('src'); + // Restore time + const onLoadedMetaData = () => { + player.currentTime = currentTime; + player.off('loadedmetadata', onLoadedMetaData); + }; + player.on('loadedmetadata', onLoadedMetaData); + // Load new source player.media.load(); @@ -107,9 +114,6 @@ const html5 = { player.play(); } - // Restore time - player.currentTime = currentTime; - // Trigger change event utils.dispatchEvent.call(player, player.media, 'qualitychange', false, { quality: input, -- cgit v1.2.3 From 4c1337b4c5e86e22c47dac1d74e3b3298bbc01cb Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Mon, 11 Jun 2018 03:21:18 +0200 Subject: Assure type safety in getSources() and getQualityOptions() (always return arrays), and remove external conditions and type conversion no longer needed --- src/js/html5.js | 53 +++++++++++------------------------------------------ 1 file changed, 11 insertions(+), 42 deletions(-) (limited to 'src/js/html5.js') diff --git a/src/js/html5.js b/src/js/html5.js index 63596cfc..a7ff0bd9 100644 --- a/src/js/html5.js +++ b/src/js/html5.js @@ -8,35 +8,21 @@ import utils from './utils'; const html5 = { getSources() { if (!this.isHTML5) { - return null; + return []; } - return this.media.querySelectorAll('source'); + return Array.from(this.media.querySelectorAll('source')); }, // Get quality levels getQualityOptions() { - if (!this.isHTML5) { - return null; - } - - // Get sources - const sources = html5.getSources.call(this); - - if (utils.is.empty(sources)) { - return null; - } - - // Get with size attribute - const sizes = Array.from(sources).filter(source => !utils.is.empty(source.getAttribute('size'))); - - // If none, bail - if (utils.is.empty(sizes)) { - return null; - } + // Get sizes from elements + const sizes = html5.getSources.call(this) + .map(source => Number(source.getAttribute('size'))) + .filter(Boolean); // Reduce to unique list - return utils.dedupe(sizes.map(source => Number(source.getAttribute('size')))); + return utils.dedupe(sizes); }, extend() { @@ -51,34 +37,17 @@ const html5 = { get() { // Get sources const sources = html5.getSources.call(player); + const [source] = sources.filter(source => source.getAttribute('src') === player.source); - if (utils.is.empty(sources)) { - return null; - } - - const matches = Array.from(sources).filter(source => source.getAttribute('src') === player.source); - - if (utils.is.empty(matches)) { - return null; - } - - return Number(matches[0].getAttribute('size')); + // Return size, if match is found + return source && Number(source.getAttribute('size')); }, set(input) { // Get sources const sources = html5.getSources.call(player); - if (utils.is.empty(sources)) { - return; - } - // Get matches for requested size - const matches = Array.from(sources).filter(source => Number(source.getAttribute('size')) === input); - - // No matches for requested size - if (utils.is.empty(matches)) { - return; - } + const matches = sources.filter(source => Number(source.getAttribute('size')) === input); // Get supported sources const supported = matches.filter(source => support.mime.call(player, source.getAttribute('type'))); -- cgit v1.2.3 From ed606c28abec076ba164ec600a743a2bdd3307f2 Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Mon, 11 Jun 2018 06:34:02 +0200 Subject: Filter out unsupported mimetypes in getSources() instead of the quality setter --- src/js/html5.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/js/html5.js') diff --git a/src/js/html5.js b/src/js/html5.js index a7ff0bd9..8f23b3c1 100644 --- a/src/js/html5.js +++ b/src/js/html5.js @@ -11,7 +11,10 @@ const html5 = { return []; } - return Array.from(this.media.querySelectorAll('source')); + const sources = Array.from(this.media.querySelectorAll('source')); + + // Filter out unsupported sources + return sources.filter(source => support.mime.call(this, source.getAttribute('type'))); }, // Get quality levels @@ -46,14 +49,11 @@ const html5 = { // Get sources const sources = html5.getSources.call(player); - // Get matches for requested size - const matches = sources.filter(source => Number(source.getAttribute('size')) === input); - - // Get supported sources - const supported = matches.filter(source => support.mime.call(player, source.getAttribute('type'))); + // Get first match for requested size + const source = sources.find(source => Number(source.getAttribute('size')) === input); - // No supported sources - if (utils.is.empty(supported)) { + // No matching source found + if (!source) { return; } @@ -66,7 +66,7 @@ const html5 = { const { currentTime, playing } = player; // Set new source - player.media.src = supported[0].getAttribute('src'); + player.media.src = source.getAttribute('src'); // Restore time const onLoadedMetaData = () => { -- cgit v1.2.3 From 6d2dad58108d4c57e573a70872136c8dbb635d74 Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Mon, 11 Jun 2018 20:41:53 +0200 Subject: Trigger qualityrequested event unconditionally when trying to set it (needed for streaming libraries to be able to listen) --- src/js/html5.js | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/js/html5.js') diff --git a/src/js/html5.js b/src/js/html5.js index 8f23b3c1..9931ae93 100644 --- a/src/js/html5.js +++ b/src/js/html5.js @@ -57,11 +57,6 @@ const html5 = { return; } - // Trigger change event - utils.dispatchEvent.call(player, player.media, 'qualityrequested', false, { - quality: input, - }); - // Get current state const { currentTime, playing } = player; -- cgit v1.2.3 From db95b3234fd38e5dd71d00876c925514960e63fc Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Mon, 11 Jun 2018 17:00:34 +0200 Subject: Move uniqueness filter from getQualityOptions to setQualityMenu --- src/js/html5.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/js/html5.js') diff --git a/src/js/html5.js b/src/js/html5.js index 9931ae93..fb2bc359 100644 --- a/src/js/html5.js +++ b/src/js/html5.js @@ -20,12 +20,9 @@ const html5 = { // Get quality levels getQualityOptions() { // Get sizes from elements - const sizes = html5.getSources.call(this) + return html5.getSources.call(this) .map(source => Number(source.getAttribute('size'))) .filter(Boolean); - - // Reduce to unique list - return utils.dedupe(sizes); }, extend() { -- cgit v1.2.3 From ee4c044d2746ffc3cb5bd5de5fe6eab6b336a11c Mon Sep 17 00:00:00 2001 From: BoHong Li Date: Tue, 12 Jun 2018 11:35:31 +0800 Subject: fix: html5.cancelRequest not remove source tag correctly --- src/js/html5.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/js/html5.js') diff --git a/src/js/html5.js b/src/js/html5.js index fb2bc359..c828dfaf 100644 --- a/src/js/html5.js +++ b/src/js/html5.js @@ -91,7 +91,7 @@ const html5 = { } // Remove child sources - utils.removeElement(html5.getSources()); + utils.removeElement(html5.getSources.call(this)); // Set blank video src attribute // This is to prevent a MEDIA_ERR_SRC_NOT_SUPPORTED error -- cgit v1.2.3 From 87170ab46080ae0d82afd1b39ab3fdf2e3ff1e62 Mon Sep 17 00:00:00 2001 From: cky <576779975@qq.com> Date: Tue, 12 Jun 2018 20:55:31 +0800 Subject: remove event listeners in destroy, add once method --- src/js/html5.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/js/html5.js') diff --git a/src/js/html5.js b/src/js/html5.js index fb2bc359..3b0b8c71 100644 --- a/src/js/html5.js +++ b/src/js/html5.js @@ -63,9 +63,8 @@ const html5 = { // Restore time const onLoadedMetaData = () => { player.currentTime = currentTime; - player.off('loadedmetadata', onLoadedMetaData); }; - player.on('loadedmetadata', onLoadedMetaData); + player.once('loadedmetadata', onLoadedMetaData); // Load new source player.media.load(); -- cgit v1.2.3 From 392dfd024c505f5ae1bbb2f0d3e0793c251a1f35 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Wed, 13 Jun 2018 00:02:55 +1000 Subject: Utils broken down into seperate files and exports --- src/js/html5.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/js/html5.js') diff --git a/src/js/html5.js b/src/js/html5.js index 63596cfc..d13e6aa6 100644 --- a/src/js/html5.js +++ b/src/js/html5.js @@ -3,7 +3,10 @@ // ========================================================================== import support from './support'; -import utils from './utils'; +import { dedupe } from './utils/arrays'; +import { removeElement } from './utils/elements'; +import { trigger } from './utils/events'; +import is from './utils/is'; const html5 = { getSources() { @@ -23,20 +26,20 @@ const html5 = { // Get sources const sources = html5.getSources.call(this); - if (utils.is.empty(sources)) { + if (is.empty(sources)) { return null; } // Get with size attribute - const sizes = Array.from(sources).filter(source => !utils.is.empty(source.getAttribute('size'))); + const sizes = Array.from(sources).filter(source => !is.empty(source.getAttribute('size'))); // If none, bail - if (utils.is.empty(sizes)) { + if (is.empty(sizes)) { return null; } // Reduce to unique list - return utils.dedupe(sizes.map(source => Number(source.getAttribute('size')))); + return dedupe(sizes.map(source => Number(source.getAttribute('size')))); }, extend() { @@ -52,13 +55,13 @@ const html5 = { // Get sources const sources = html5.getSources.call(player); - if (utils.is.empty(sources)) { + if (is.empty(sources)) { return null; } const matches = Array.from(sources).filter(source => source.getAttribute('src') === player.source); - if (utils.is.empty(matches)) { + if (is.empty(matches)) { return null; } @@ -68,7 +71,7 @@ const html5 = { // Get sources const sources = html5.getSources.call(player); - if (utils.is.empty(sources)) { + if (is.empty(sources)) { return; } @@ -76,7 +79,7 @@ const html5 = { const matches = Array.from(sources).filter(source => Number(source.getAttribute('size')) === input); // No matches for requested size - if (utils.is.empty(matches)) { + if (is.empty(matches)) { return; } @@ -84,12 +87,12 @@ const html5 = { const supported = matches.filter(source => support.mime.call(player, source.getAttribute('type'))); // No supported sources - if (utils.is.empty(supported)) { + if (is.empty(supported)) { return; } // Trigger change event - utils.dispatchEvent.call(player, player.media, 'qualityrequested', false, { + trigger.call(player, player.media, 'qualityrequested', false, { quality: input, }); @@ -115,7 +118,7 @@ const html5 = { } // Trigger change event - utils.dispatchEvent.call(player, player.media, 'qualitychange', false, { + trigger.call(player, player.media, 'qualitychange', false, { quality: input, }); }, @@ -130,7 +133,7 @@ const html5 = { } // Remove child sources - utils.removeElement(html5.getSources()); + removeElement(html5.getSources()); // Set blank video src attribute // This is to prevent a MEDIA_ERR_SRC_NOT_SUPPORTED error -- cgit v1.2.3 From 94055f0772c6c5febcfe1e35714ae3e88afaaf35 Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Tue, 19 Jun 2018 00:24:27 +0200 Subject: Replace filter()[0] with find() --- src/js/html5.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/js/html5.js') diff --git a/src/js/html5.js b/src/js/html5.js index 6aa96f4c..3c9f1030 100644 --- a/src/js/html5.js +++ b/src/js/html5.js @@ -39,7 +39,7 @@ const html5 = { get() { // Get sources const sources = html5.getSources.call(player); - const [source] = sources.filter(source => source.getAttribute('src') === player.source); + const source = sources.find(source => source.getAttribute('src') === player.source); // Return size, if match is found return source && Number(source.getAttribute('size')); -- cgit v1.2.3 From d72e502107b24a629572f6dcac3fdc4c95ea9001 Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Tue, 19 Jun 2018 03:34:07 +0200 Subject: Fixes #1044: Don't load the new source if preload is disabled and the current source hasn't been loaded --- src/js/html5.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/js/html5.js') diff --git a/src/js/html5.js b/src/js/html5.js index 3c9f1030..0876211a 100644 --- a/src/js/html5.js +++ b/src/js/html5.js @@ -57,23 +57,25 @@ const html5 = { } // Get current state - const { currentTime, playing } = player; + const { currentTime, paused, preload, readyState } = player.media; // Set new source player.media.src = source.getAttribute('src'); - // Restore time - const onLoadedMetaData = () => { - player.currentTime = currentTime; - }; - player.once('loadedmetadata', onLoadedMetaData); + // Prevent loading if preload="none" and the current source isn't loaded (#1044) + if (preload !== 'none' || readyState) { + // Restore time + player.once('loadedmetadata', () => { + player.currentTime = currentTime; - // Load new source - player.media.load(); + // Resume playing + if (!paused) { + player.play(); + } + }); - // Resume playing - if (playing) { - player.play(); + // Load new source + player.media.load(); } // Trigger change event -- cgit v1.2.3 From 211ad6c8f59c3d48648f8be0bc1cde85fd72ea95 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Mon, 13 Aug 2018 23:43:08 +1000 Subject: Removed YouTube quality controls --- src/js/html5.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/js/html5.js') diff --git a/src/js/html5.js b/src/js/html5.js index 0876211a..fc8da8c0 100644 --- a/src/js/html5.js +++ b/src/js/html5.js @@ -82,6 +82,9 @@ const html5 = { triggerEvent.call(player, player.media, 'qualitychange', false, { quality: input, }); + + // Save to storage + player.storage.set({ quality: input }); }, }); }, -- cgit v1.2.3 From a86bbae85145a22d0ed7f259fe86fe82b86dd7ff Mon Sep 17 00:00:00 2001 From: Robin van Nunen Date: Sat, 29 Sep 2018 21:23:10 +0200 Subject: Only save quality setting when it's updated by the user. Fixes bug in html5 player where it would override the settings if the current video does not support the given quality. --- src/js/html5.js | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/js/html5.js') diff --git a/src/js/html5.js b/src/js/html5.js index fc8da8c0..0876211a 100644 --- a/src/js/html5.js +++ b/src/js/html5.js @@ -82,9 +82,6 @@ const html5 = { triggerEvent.call(player, player.media, 'qualitychange', false, { quality: input, }); - - // Save to storage - player.storage.set({ quality: input }); }, }); }, -- cgit v1.2.3