Both YouTube and Vimeo provide JavaScript APIs that allow you to control embedded videos - play, pause, and more. To use these APIs effectively, there are a few setup requirements worth noting.
YouTube
- Include
enablejsapi=1
in the iframesrc
parameters - To use the 'playVideo' method include
mute=1
in the iframesrc
parameters - Include the YouTube Player API
<script src="https://www.youtube.com/iframe_api"></script>
You can now use the postMessage JavaScript method to execute the Player API methods
Vimeo
- Include
api=1
and in the iframesrc
parameters - To use the 'play' method include
muted=1
in the iframesrc
parameters - Include the Vimeo Player SDK
<script src="https://player.vimeo.com/api/player.js"></script>
You can now use the postMessage JavaScript method to execute the Player SDK methods