Preventing YouTube from being cached in the browser until the image is clicked.
How would I be able to do this, because I can’t figure it out.
It’s the " player_api " that’s still being caught in the browser. How would I be able to prevent that until the image is clicked?
Code:
https://jsfiddle.net/hzyrfkwb/185/
Html:
<script type="text/javascript" src="https://www.youtube.com/player_api"></script>
Javascript:
"use strict";
const hide = (el) => el.classList.add("hide");
function coverClickHandler(evt) {
const cover = evt.currentTarget;
hide(cover);
}
const cover = document.querySelector(".jacketc");
cover.addEventListener("click", coverClickHandler);
}());
const videoPlayer = (function makeVideoPlayer() {
"use strict";
function onPlayerReady(event) {
const player = event.target;
player.setVolume(50); // percent
}
function onPlayerStateChange(event) {
const player = event.target;
const playerVars = player.b.b.playerVars;
if (playerVars.loop && event.data === YT.PlayerState.ENDED) {
player.seekTo(playerVars.start);
}
}
function addVideo(video) {
const videoId = video.getAttribute("data-id");
new YT.Player(video, {
width: 606,
height: 344,
videoId: videoId,
playerVars: {
autoplay: 1,
controls: 1,
showinfo: 1,
rel: 0,
iv_load_policy: 3,
cc_load_policy: 0,
fs: 0,
disablekb: 1,
loop: true,
start: 200,
end: 204
},
events: {
"onReady": onPlayerReady,
"onStateChange": onPlayerStateChange
}
});
}
function init(opts) {
addVideo(opts.video, opts.playerVars || {});
}
return {
init
};
}());
(function iife() {
"use strict";
const show = (el) => el.classList.remove("hide");
function coverClickHandler(evt) {
const wrapper = evt.currentTarget.nextElementSibling;
show(wrapper);
videoPlayer.init({
video: wrapper.querySelector(".video")
});
}
const cover = document.querySelector(".jacketc");
cover.addEventListener("click", coverClickHandler);
}());