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

How To Migrate MVC 3 Application To MVC 5

Populate a drop-down in Vue.js and Asp.net Core from an ajax call

Building a CRUD Application with Ag-Grid