How to destroy video

Viewed 118

I have never used player.destroy(); before in code so I am unsure of how to add it.

How should it be written into the code?

I am using it to destroy the iframe for the video, when the X button is clicked.

After a svg play button is clicked, there is an X button that you press which when pressed, destroys the video.

Are either of these the right way?

Click Run, not update to test code:

Like this: https://jsitor.com/RTH542DH1o

function createResetHandler(player) {
    const resetVideos = document.querySelectorAll('.exit');
    resetVideos.forEach(function resetVideoHandler(video) {
      video.addEventListener('click', function resetVideoHandler() {
        if (!player) {
        } else {
          player.stopVideo();
          player.destroy();
          player = null; 
        }
      });
    });
  }

or like this: https://jsitor.com/xaLXppyXJ5

 function createResetHandler(player) {
    const resetVideos = document.querySelectorAll('.exit');
    resetVideos.forEach(function resetVideoHandler(video) {
      video.addEventListener('click', function resetVideoHandler() {

        player.destroy();

      });
    });
  }

or would it be written a different way?

https://developers.google.com/youtube/iframe_api_reference

Removes the <iframe> containing the player.

0 Answers
Related