Title: Can&#8217;t pause video programmatically
Last modified: November 5, 2019

---

# Can’t pause video programmatically

 *  [its2easy](https://wordpress.org/support/users/its2easy/)
 * (@its2easy)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cant-pause-video-programmatically/)
 * There is a slider in which the video should stop when changing slide.
    It worked
   well without lazy load:
 *     ```
       ...
       get slide
       ...
       var iframe = slide.getElementsByTagName("iframe")[0];
       if (iframe) {
         iframe.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
       }
       ```
   
 * Default html was:
 *     ```
       <div class='embed-responsive embed-responsive-16by9'>
           <iframe class='embed-responsive-item' src='https://www.youtube.com/embed/f98z9tqweqwe?enablejsapi=1' frameborder='0' allow='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>
       </div>
       ```
   
 * And when I enable lazy load and use lyte_preparse it works, but no longer pause
   after slide change, with no errors. I know that iframe.contentWindow.postMessage
   requires enablejsapi=1, but it also presents in plugin generetad iframe. What
   can be wrong?

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cant-pause-video-programmatically/#post-12098468)
 * as far as I know a LYTE triggered iframe does _not_ come with `enablejsapi=1`,
   to that’s probably reason?
 *  Thread Starter [its2easy](https://wordpress.org/support/users/its2easy/)
 * (@its2easy)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cant-pause-video-programmatically/#post-12098609)
 * yes, my mistake, when I pass simple url there is no enablejsapi.
    But if I pass
   url with parameter, like lyte_preparse(‘[https://www.youtube.com/watch?v=u9Iti2qxKsc?enablejsapi=1&#8217](https://www.youtube.com/watch?v=u9Iti2qxKsc?enablejsapi=1&#8217);),
   it generates iframe with this parameter
 *     ```
       <div class="lyte qsa_\&enablejsapi\=1\&origin\=http://domain.local/ lP" id="WYL_u9Iti2qxKsc"><iframe id="iF_u9Iti2qxKsc" width="1280" height="360" src="https://www.youtube-nocookie.com/embed/f98z9tqweqwe?autoplay=1&controls=1&wmode=opaque&rel=0&egm=0&iv_load_policy=3&hd=0&enablejsapi=1&origin=http://domain.local/" frameborder="0" style="" allowfullscreen="" allow="autoplay"></iframe></div>
       ```
   
 * but still not working as if there is no this parameter
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cant-pause-video-programmatically/#post-12098624)
 * in that case; no idea I’m afraid, don’t know the YT JS API well enough to comment:-/
 *  Thread Starter [its2easy](https://wordpress.org/support/users/its2easy/)
 * (@its2easy)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cant-pause-video-programmatically/#post-12098751)
 * Thank you for your replies
    P.S. I tried several ways and it seems like “origin
   =http://domain.local/” (which is automatically added by plugin if the url contains
   enablejsapi) breaks youtube api because of the last slash. With “origin=http://
   domain.local” or without any origin in the query it works as expected
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cant-pause-video-programmatically/#post-12098784)
 * great find! OK, can you [in wp-youtube-lyte.php on line 94](https://github.com/futtta/wp-youtube-lyte/blob/0802f3e781c7bd063bf782c3b31a45b4056d90b7/wp-youtube-lyte.php#L94)
   change
 * `$origin=$urlArr['scheme']."://".$urlArr['host']."/";`
    into `$origin=$urlArr['
   scheme']."://".$urlArr['host'];`
 * and re-test?
 *  Thread Starter [its2easy](https://wordpress.org/support/users/its2easy/)
 * (@its2easy)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cant-pause-video-programmatically/#post-12098828)
 * Now working in both local and production environments
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cant-pause-video-programmatically/#post-12098936)
 * OK, I’ll make sure this goes into the next update!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Can’t pause video programmatically’ is closed to new replies.

 * ![](https://ps.w.org/wp-youtube-lyte/assets/icon-128x128.png?rev=1836005)
 * [WP YouTube Lyte](https://wordpress.org/plugins/wp-youtube-lyte/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-youtube-lyte/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-youtube-lyte/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-youtube-lyte/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-youtube-lyte/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-youtube-lyte/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * Last activity: [6 years, 7 months ago](https://wordpress.org/support/topic/cant-pause-video-programmatically/#post-12098936)
 * Status: not resolved