Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #401172

    I’ve got this script in my functions.php but it doesn’t work.

    add_action('wp_footer', 'ava_current_menu');
    function ava_current_menu(){ if(is_page('home')) {
    ?>
    <!-- **teera -->
    <!-- <script async src="https://www.youtube.com/iframe_api"></script> -->
    <script>
    var tag = document.createElement('script');
    
          tag.src = "https://www.youtube.com/iframe_api";
          var firstScriptTag = document.getElementsByTagName('script')[0];
          firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    var ytplayer;
    
      function onYouTubeIframeAPIReady() {
      ytplayer = new YT.Player('vid', {
    events: {
    		'onReady': onPlayerReady,
                'onStateChange': onPlayerStateChange
              }
    });  
    console.log('yt_api working');
      }
    
    function onPlayerReady(event){
    console.log('playeready');
    return null;
    }
    
    function onPlayerStateChange(event) {
    console.log('yt_change');
    video_stop();
    return null;
          }
    
    function video_stop(){
    var q = document.getElementsByTagName("video");
    var i;
    for (i = 0; i < q.length; i++){
    q[i].pause();
    console.log('videostop');
    }
    
    };
    
    jQuery('a').click(function(){
    console.log('aclick');
    video_stop();
    ytplayer.pauseVideo();
    });
    
    </script>
    <?php
    }}

    This section

    var tag = document.createElement('script');
    
          tag.src = "https://www.youtube.com/iframe_api";
          var firstScriptTag = document.getElementsByTagName('script')[0];
          firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

    Came straight off youtube iframe_api_reference and is supposed to load the iframe api code asynchronously.

    If I replace it with <script async src=”https://www.youtube.com/iframe_api”></script&gt;

    The script will load properly most times, but not always (just keep hitting refresh). But still you have browsers that do not support async and the script still doesn’t always load. In the times it does load, it still has problems with onStateChange not triggering when I play the video.

    This script works when written for simple HTML page but isn’t working with enfold reliably for some reason.

    Thanks,
    Teera

    • This topic was modified 9 years, 8 months ago by teeramusic.
    #401560

    Hi teeramusic!

    Not sure about that. It’s kind of bordering on custom work though.

    Are you just trying to display youtube videos? We have a video shortcode.

    Best regards,
    Elliott

    #401943

    I agree, it’s kind of bordering on custom work, but at the same time, if it works on a regular HTML page it should also work in Enfold unless Enfold has done something quirky with the script?

    I’m trying to stop all the other videos automatically except for the one that is playing so that there can only be one video playing at any given moment.

    Thanks,
    Teera

    #402827

    Hey!

    I haven’t played around with the video APIs that much but you can see where we interact with it in /enfold/js/shortcodes.js on lines 647 – 1141.

    It should only be creating players on these elements though,

    $('.avia-slideshow iframe[src*="youtube.com"], .av_youtube_frame, .avia-slideshow iframe[src*="vimeo.com"], .avia-slideshow video').aviaVideoApi({}, 'li');
    

    Cheers!
    Elliott

    #403173

    I’ll have a look :)

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Event watches not firing reliably / scripts not loading.’ is closed to new replies.