1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to auto play youtube video and keep it silent?

Discussion in 'YouTube' started by Hawkster, Jun 1, 2015.

  1. Hawkster

    Hawkster Jr. VIP Jr. VIP

    Joined:
    Jun 22, 2013
    Messages:
    3,423
    Likes Received:
    3,615
    Gender:
    Male
    Occupation:
    Listen to everyone - Follow no-one
    Location:
    UK
    Home Page:
    Any of you smart guys know how to manipulate the YouTube embed code so that the video will auto play silently?
     
  2. nglbh

    nglbh Registered Member

    Joined:
    Jan 4, 2011
    Messages:
    93
    Likes Received:
    182
    Code:
     <div id="player"></div>    <script>
          // 2. This code loads the IFrame Player API code 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);
    
    
          // 3. This function creates an <iframe> (and YouTube player)
          //    after the API code downloads.
          var player;
          function onYouTubeIframeAPIReady() {
            player = new YT.Player('player', {
              height: '195',
              width: '260',
              videoId: 'h3P1OR9gg2Y',
              events: {
                'onReady': onPlayerReady,
                'onStateChange': onPlayerStateChange
              }
            });
          }
    
    
          // 4. The API will call this function when the video player is ready.
          function onPlayerReady(event) {
               event.target.setVolume(0);
           event.target.playVideo();
          }
    
    
          // 5. The API calls this function when the player's state changes.
          //    The function indicates that when playing a video (state=1),
          //    the player should play for six seconds and then stop.
          var done = false;
          function onPlayerStateChange(event) {
            if (event.data == YT.PlayerState.PLAYING && !done) {
        //      setTimeout(stopVideo, 6000);
                      done = true;
            }
               event.target.setVolume(0);
          }
        </script>
    Tested on localhost and works just fine, the only problem is that I can't see the volume button

    Let us now

    NgL
     
    • Thanks Thanks x 2
  3. markharmer

    markharmer Registered Member

    Joined:
    Sep 13, 2013
    Messages:
    63
    Likes Received:
    4
    Location:
    Dubai
    agree,But only work on private blog
     
  4. gutterleech

    gutterleech Regular Member

    Joined:
    Sep 30, 2010
    Messages:
    356
    Likes Received:
    283
    Occupation:
    founder
    Location:
    Third World
    • Thanks Thanks x 2
  5. ripon65

    ripon65 BANNED BANNED

    Joined:
    May 10, 2015
    Messages:
    134
    Likes Received:
    38
    Gender:
    Male
    You can use different web plugin bro :)
     
  6. Repulsor

    Repulsor Power Member

    Joined:
    Jun 11, 2013
    Messages:
    766
    Likes Received:
    275
    Location:
    PHP Scripting ;)
    Looks like a cool way to actually generate views off website visitors without them knowing about it. :D
     
    • Thanks Thanks x 2
  7. Hawkster

    Hawkster Jr. VIP Jr. VIP

    Joined:
    Jun 22, 2013
    Messages:
    3,423
    Likes Received:
    3,615
    Gender:
    Male
    Occupation:
    Listen to everyone - Follow no-one
    Location:
    UK
    Home Page:
    I should have added more detail. What i want to do is place a video in the sidebar on my site or even in the footer, that will play automatically (and silently when someone visits my site. Im not sure how to use the code you provided but thanks for your time.

    Useful but useless for what i want. Thanks anyway


    Thats exactly what im hoping to do lol

     
    • Thanks Thanks x 1
  8. ShazzyBlackhat

    ShazzyBlackhat Junior Member

    Joined:
    May 2, 2015
    Messages:
    184
    Likes Received:
    57
    I am interested to know this method as well. I know what OP is trying to do here. ;)
     
  9. nglbh

    nglbh Registered Member

    Joined:
    Jan 4, 2011
    Messages:
    93
    Likes Received:
    182
    If you're using wp you can add a simple text widget in the sidebar with the code I posted:

    [​IMG]

    [​IMG]
     
  10. ryanb248

    ryanb248 Newbie

    Joined:
    Jun 4, 2015
    Messages:
    2
    Likes Received:
    0
    they fixed this, they should all now play fine
     
  11. Plus44

    Plus44 Power Member

    Joined:
    Dec 14, 2014
    Messages:
    644
    Likes Received:
    245
    Gender:
    Male
    Location:
    US
    <iframe width="560" height="315" src="https://www.youtube.com/embed/rFtam2eAkfo" frameborder="0" "allowfullscreen" volume="0"></iframe>

    Try that in the embed code. Not sure if that works anymore. YouTube changes a lot.