Play ,Pause and Stop Embedded YouTube Video Iframe




Reference  

<script  src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

HTML Code 


<div><a href="#" class="play-video">Play Video</a></div>
<div><a href="#" class="stop-video">Stop Video</a></div>
<div><a href="#" class="pause-video">Pause Video</a></div>



<iframe width="560" height="315" src="https://www.youtube.com/embed/WWLsLiVYJRU?enablejsapi=1" frameborder="0"  class="youtube-video" allowfullscreen></iframe>



JQuery Code 

$('a.play-video').click(function(){
       $('.youtube-video')[0].contentWindow.postMessage('{"event":"command","func":"' + 'playVideo' + '","args":""}', '*');
});

$('a.stop-video').click(function(){
       $('.youtube-video')[0].contentWindow.postMessage('{"event":"command","func":"' + 'stopVideo' + '","args":""}', '*');
});

$('a.pause-video').click(function(){
       $('.youtube-video')[0].contentWindow.postMessage('{"event":"command","func":"' + 'pauseVideo' + '","args":""}', '*');
});


Note:
        You have need To add ?enablejsapi=1  in Url. if You Not add This this Code is not work 



Popular posts from this blog

Periodic Restart Settings for Application Pool Recycling

Generate image ,pdf and Video Thumb using node js

How to receive JSON object in POST and GET using web api