• 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

    (@optimizingmatters)

    as far as I know a LYTE triggered iframe does not come with enablejsapi=1, to that’s probably reason?

    Thread Starter its2easy

    (@its2easy)

    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;), 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

    (@optimizingmatters)

    in that case; no idea I’m afraid, don’t know the YT JS API well enough to comment :-/

    Thread Starter its2easy

    (@its2easy)

    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

    (@optimizingmatters)

    great find! OK, can you in wp-youtube-lyte.php on line 94 change

    $origin=$urlArr['scheme']."://".$urlArr['host']."/";
    into
    $origin=$urlArr['scheme']."://".$urlArr['host'];

    and re-test?

    Thread Starter its2easy

    (@its2easy)

    Now working in both local and production environments

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    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.