SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    819
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question YouTube 'playerVars autoplay' set to 0; still autoplaying

    With this script, I'm using 'playerVars autoplay: 0' to prevent the video from autoplaying, but it seems to still be autoplaying.

    PHP Code:
    <script type="text/javascript">// <![CDATA[
    /**
         * Put your video IDs in this array
         */
        
    var videoIDs = [
            
    'q_fso9SsG-g',
            
    'Mv-MS8s3mMc'
        
    ];
        var 
    playercurrentVideoId 0;
        function 
    onYouTubeIframeAPIReady() {
            
    player = new YT.Player('player', {
                
    height'252',
                
    width'300',
        
    playerVars: { 'rel'0'autoplay'},
    autoplay'0',
                
    events: {
                    
    'onReady'onPlayerReady,
                    
    'onStateChange'onPlayerStateChange
                
    }
            });
        }
        function 
    onPlayerReady(event) {
            
    event.target.loadVideoById(videoIDs[currentVideoId]);
        }
        function 
    onPlayerStateChange(event) {
            if (
    event.data == YT.PlayerState.ENDED) {
                
    currentVideoId++;
                if (
    currentVideoId videoIDs.length) {
                    
    player.loadVideoById(videoIDs[currentVideoId]);
                }
            }
        }
    // ]]></script> 

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    In your onPlayerReady event binding you are immediately calling loadVideoById which by default automatically plays the video, is there a reason why you need to do this as you can pass the video ID as a parameter.
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  3. #3
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    819
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Trying to play videos consecutively and am open to a different method if it would help alleviate the annoying Autoplay.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •