From 093af22942947809b7805f82bb12ca615c13383c Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sun, 12 Jul 2015 21:17:56 +1000 Subject: More work on YouTube playback --- src/js/plyr.js | 195 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 151 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/js/plyr.js b/src/js/plyr.js index 5d43fb0b..4e3a7431 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -49,10 +49,9 @@ duration: ".player-duration" }, classes: { - video: "player-video", videoWrapper: "player-video-wrapper", embedWrapper: "player-video-embed", - audio: "player-audio", + type: "player-{0}", stopped: "stopped", playing: "playing", muted: "muted", @@ -83,10 +82,7 @@ key: "plyr_volume" }, controls: ["restart", "rewind", "play", "fast-forward", "current-time", "duration", "mute", "volume", "captions", "fullscreen"], - onSetup: function() {}, - youtube: { - regex: /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ - } + onSetup: function() {} }; // Build the default HTML @@ -833,7 +829,7 @@ player.media.removeAttribute("controls"); // Add type class - _toggleClass(player.container, config.classes[player.type], true); + _toggleClass(player.container, config.classes.type.replace("{0}", player.type), true); // If there's no autoplay attribute, assume the video is stopped and add state class _toggleClass(player.container, config.classes.stopped, (player.media.getAttribute("autoplay") === null)); @@ -854,14 +850,11 @@ // Cache the container player.videoContainer = wrapper; + } - // YouTube - var firstSource = player.media.querySelectorAll("source")[0], - matches = firstSource.src.match(config.youtube.regex); - - if(firstSource.type == "video/youtube" && matches && matches[2].length == 11) { - _setupYouTube(matches[2]); - } + // YouTube + if(player.type == "youtube") { + _setupYouTube(player.media.getAttribute("data-video-id")); } } @@ -873,21 +866,17 @@ // Setup YouTube function _setupYouTube(id) { - player.embed = true; - - // Hide the