Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3638

How to have the same video be able to autoplay on its own a 2nd time

$
0
0

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    }  };

Viewing all articles
Browse latest Browse all 3638

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>