Currently, the same video is only able to autoplay 1 time.
To reproduce: Click 1 svg play button, then click the X.
Then click the same svg play button a 2nd time.
You will find that the video does not autoplay.
How is that fixed in the code so that the same video can autoplay a 2nd time?
Click Run, not update to test code: https://jsitor.com/uSDGY51epP
Backup copy: https://jsfiddle.net/wzefmv34/
const videoPlayer = (function makeVideoPlayer() { const players = []; const tag = document.createElement("script"); tag.src = "https://www.youtube.com/player_api"; const firstScriptTag = document.getElementsByTagName("script")[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); function createStopHandler(player) { const stopButtons = document.querySelectorAll(".exit"); stopButtons.forEach(function stopButtonHandler(buttons) { buttons.addEventListener("click", function buttonClickHandler() { player.stopVideo(); }); }); } function onPlayerReady(event) { const player = event.target; player.setVolume(100); createStopHandler(player); } function addPlayer(video, settings) { const defaults = { height: 360, host: "https://www.youtube-nocookie.com", videoId: video.dataset.id, width: 640 }; defaults.events = { onReady: onPlayerReady }; const playerOptions = combinePlayerOptions(defaults, settings); const player = new YT.Player(video, playerOptions); players.push(player); return player; } return { addPlayer };}());const managePlayer = (function makeManagePlayer() { const defaults = { playerVars: { autoplay: 1, controls: 1, disablekb: 1, enablejsapi: 1, fs: 0, iv_load_policy: 3 } };