Skip to:
Content
Pages
Categories
Search
Top
Bottom

Buddypress and youtube iframe API


  • nownesx
    Participant

    @nownesx

    Hi,

    I’m trying to implement controls to any video in the activity stream. It seems to work (for the last video post) but when I click on the “load more” button, new posts are empty.

    This is the code:

    //Load player api asynchronously.
            var tag = document.createElement('script');  
            tag.src = "https://www.youtube.com/iframe_api";  
            var firstScriptTag = document.getElementsByTagName('script')[0];  
            firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 
    
           <div class="video-container">
            <div data-id="olBOo_S5AHY"></div>
            </div>
            <div class="video-container">
                <div data-id="3IXKIVZ9T-U"></div>
            </div>
            <div class="video-container">
                <div data-id="LAQDcnwwspQ"></div>
           </div>
    
        function onYouTubePlayerAPIReady() {
            var players = document.querySelectorAll('.video-container div')
            for (var i = 0; i < players.length; i++) {
                new YT.Player(players[i], {
                    playerVars: {
                        'autoplay': 0,
                        'modestbranding': 1,
                    },
                    videoId: players[i].dataset.id
                });
            }
        }
  • You must be logged in to reply to this topic.
Skip to toolbar