Youtube video stop on pause event
<p>I have several youtube iframes with TV channels on my website page. </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div&gt;
&lt;iframe id="ytplayer"  src="https://www.youtube.com/embed/ntBxGznOML0?rel=0&amp;enablejsapi=1&amp;autoplay=0&amp;controls=1&amp;showinfo=0&amp;loop=1&amp;iv_load_policy=3&amp;modestbranding=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;iframe id="ytplayer"  src="https://www.youtube.com/embed/zl4aeAfhdro?rel=0&amp;enablejsapi=1&amp;autoplay=0&amp;controls=1&amp;showinfo=0&amp;loop=1&amp;iv_load_policy=3&amp;modestbranding=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;iframe id="ytplayer"  src="https://www.youtube.com/embed/URD4UWm-edg?rel=0&amp;enablejsapi=1&amp;autoplay=0&amp;controls=1&amp;showinfo=0&amp;loop=1&amp;iv_load_policy=3&amp;modestbranding=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;iframe id="ytplayer"  src="https://www.youtube.com/embed/75j9l956bVs?rel=0&amp;enablejsapi=1&amp;autoplay=0&amp;controls=1&amp;showinfo=0&amp;loop=1&amp;iv_load_policy=3&amp;modestbranding=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
</p>

<p>I'm trying to use one java script to play video muted and to stop it on pause event but it doesnt work for me. The script is following </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var player;

function onYouTubeIframeAPIReady() {
    player = new YT.Player('ytplayer', {
        events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
            
        }
    });
}
function onPlayerStateChange(event){
     player.stopVideo(0);
         
  }
   

}
function onPlayerReady(event) {
    player.mute();
    player.playVideo();
}</code></pre>
</div>
</div>
</p>

<p>I need to full stop video on pause event, because it is live tv channel, so if I press pause now, in 10 minutes I will get a record but not a live stream. How can I make my script work?</p>