aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/plugins/youtube.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2018-06-17 00:40:28 +1000
committerGitHub <noreply@github.com>2018-06-17 00:40:28 +1000
commitccc2608cf62f1406c3d626ed8dbd31f1acd714ce (patch)
tree0881e678c29c6e147c254b10f490768858df673a /src/js/plugins/youtube.js
parentde45de0e0bbfdea63977427d70fea503274e39b6 (diff)
parent115f352ade7fbe133a42fd434dbcc1fca13287a7 (diff)
downloadplyr-ccc2608cf62f1406c3d626ed8dbd31f1acd714ce.tar.lz
plyr-ccc2608cf62f1406c3d626ed8dbd31f1acd714ce.tar.xz
plyr-ccc2608cf62f1406c3d626ed8dbd31f1acd714ce.zip
Merge pull request #1039 from friday/poster-race-conditions
Fix poster race conditions
Diffstat (limited to 'src/js/plugins/youtube.js')
-rw-r--r--src/js/plugins/youtube.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/js/plugins/youtube.js b/src/js/plugins/youtube.js
index e383e50f..65b6db75 100644
--- a/src/js/plugins/youtube.js
+++ b/src/js/plugins/youtube.js
@@ -158,10 +158,15 @@ const youtube = {
// Replace the <iframe> with a <div> due to YouTube API issues
const videoId = parseId(source);
const id = generateId(player.provider);
- const container = createElement('div', { id });
+
+ // Get poster, if already set
+ const { poster } = player;
+
+ // Replace media element
+ const container = createElement('div', { id, poster });
player.media = replaceElement(container, player.media);
- // Set poster image
+ // Id to poster wrapper
const posterSrc = format => `https://img.youtube.com/vi/${videoId}/${format}default.jpg`;
// Check thumbnail images in order of quality, but reject fallback thumbnails (120px wide)
@@ -174,7 +179,8 @@ const youtube = {
if (!posterSrc.includes('maxres')) {
player.elements.poster.style.backgroundSize = 'cover';
}
- });
+ })
+ .catch(() => {});
// Setup instance
// https://developers.google.com/youtube/iframe_api_reference