3

I am trying from 3 days to autoplay the youtube embedded video in google chrome with "Sound Unmuted" but it is not working. While the same video with same code works in mozilla firefox. I have tried different codes but no success till now.

Here is the code.

<head>
    <style>
        body{
            margin-left: 0px;
        }
    </style>
</head> 
<script src="js/jquery-3.1.1.min.js"></script>
<div id="YouTubeVideoPlayer"></div>

<script async src="https://www.youtube.com/iframe_api"></script>
<script>
 function onYouTubeIframeAPIReady() {
  var player;
  player = new YT.Player('YouTubeVideoPlayer', {
    videoId: 'M7lc1UVf-VE', // YouTube Video ID
    width: 560,               // Player width (in px)
    height: 316, 
    start:0,             // Player height (in px)
    playerVars: {
      autoplay: 1,        // Auto-play the video on load
      controls: 1,        // Show pause/play buttons in player
      showinfo: 0,        // Hide the video title
      modestbranding: 1,  // Hide the Youtube Logo
      loop: 1,            // Run the video in a loop
      fs: 0,              // Hide the full screen button
      cc_load_policy: 0, // Hide closed captions
      iv_load_policy: 3,  // Hide the Video Annotations
      autohide: 0         // Hide video controls when playing
    },
    events: {
      onReady: function(e) {
       e.target.setVolume(40);
      }
    }
  });
 }

$("body").animate({ margin: "400px 0px 0px 0px" }, 18000 );

</script>
jeb
  • 78,592
  • 17
  • 171
  • 225
dev
  • 555
  • 1
  • 13
  • 31
  • can you or have you tried following [this](https://developers.google.com/youtube/player_parameters) documentation ? – Towkir Nov 04 '18 at 08:33
  • @Towkir yeah I have also tried code from this page. – dev Nov 04 '18 at 08:37
  • 1
    Found the answer: https://stackoverflow.com/questions/50290601/youtube-iframe-src-autoplay-not-working-in-chrome-browser/50323662 – Daniël Visser Nov 04 '18 at 08:59
  • @dev , your code works perfectly on my end. Just created an html file with your code, and it works. Though it does not work when I try to create a code snippet in the answer section. may be because it's in an iframe. – Towkir Nov 04 '18 at 09:04

1 Answers1

2

You need mute set to 0 and after the video starts you need to make a trigger at 0:01s to rise the volume back to 40.

cigien
  • 57,834
  • 11
  • 73
  • 112
Tiby Dinu
  • 21
  • 2