Results 1 to 3 of 3

Thread: YouTube loop autoplay

  1. #1
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    914
    Thanks
    118
    Thanked 2 Times in 2 Posts

    Default YouTube loop autoplay

    Hey all,

    You can see the following code being used on this site: http://www.brunomazereel.com

    Code:
    <script src="http://www.youtube.com/player_api"></script>
    <script type="text/javascript">
    var player;
    
    function onYouTubePlayerAPIReady() {
        player = new YT.Player('player', {
            playerVars: {
                'autoplay': 1,
                'controls': 0,
                'autohide': 1,
                'wmode': 'opaque',
                'showinfo': 0,
                'loop': 1,
                'playlist': 'MAtwgOsycc0'
            },
            videoId: 'MAtwgOsycc0',
            events: {
                'onReady': onPlayerReady
            }
        });
    
    }
    
    function onPlayerReady(event) {
        event.target();
        $('#text').fadeIn(400);
    }
    
    $(window).scroll(function() {
       var hT = $('.m-video').height(),
           wS = $(this).scrollTop();
       if (wS > hT) {
          player.pauseVideo();
       }
       else {
          player.playVideo();
       }
    });
    </script>
    The video starts automatically.
    Now I would like another video to start straight after that one, so I adjusted this part adding another video:

    Code:
                'playlist': 'MAtwgOsycc0,Pq_0xbfiePs'
            },
            videoId: 'MAtwgOsycc0,Pq_0xbfiePs',
    It works, the second video starts immediately after the first one, but now the first video doesn't start automatically anymore.
    Any idea how that can be resolved, please?
    Thanks!

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,846
    Thanks
    49
    Thanked 251 Times in 243 Posts
    Blog Entries
    56

    Default

    This should work. Not tested though
    Code:
    <script src="http://www.youtube.com/player_api"></script>
    <script>
    var player;
    
    function onYouTubePlayerAPIReady() {
    player = new YT.Player('player', {
    playerVars: {
    'autoplay': 1,
    'controls': 0,
    'autohide': 1,
    'wmode': 'opaque',
    'showinfo': 0,
    'loop': 1,
    'playlist': 'Pq_0xbfiePs'
    },
    videoId: 'MAtwgOsycc0',
    events: {
    'onReady': onPlayerReady
    }
    });
    
    }
    
    function onPlayerReady(event) {
    event.target();
    $('#text').fadeIn(400);
    }
    
    $(window).scroll(function() {
    var hT = $('.m-video').height(),
    wS = $(this).scrollTop();
    if (wS > hT) {
    player.pauseVideo();
    }
    else {
    player.playVideo();
    }
    });
    </script>

  3. The Following User Says Thank You to molendijk For This Useful Post:

    chechu (01-10-2017)

  4. #3
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    914
    Thanks
    118
    Thanked 2 Times in 2 Posts

    Default

    Works perfectly, thanks.
    To add more videos, just continue like this:
    Code:
    'playlist': 'nvENEbvSMW4,gjElHVZ4f14'
    },
    videoId: 'MAtwgOsycc0',

Similar Threads

  1. Replies: 8
    Last Post: 03-17-2016, 04:51 PM
  2. Youtube autoplay and loop
    By mlegg in forum HTML
    Replies: 8
    Last Post: 11-18-2014, 01:56 PM
  3. IPB forum Youtube autoplay?
    By y.sen in forum HTML
    Replies: 1
    Last Post: 08-23-2013, 12:37 AM
  4. Youtube Autoplay and Autoclose?
    By ceerup in forum Looking for such a script or service
    Replies: 1
    Last Post: 05-22-2012, 01:13 PM
  5. Replies: 3
    Last Post: 04-26-2009, 03:10 AM

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
  •