Ad Under Header

Membuat Youtube embed autoplay di mobile device

Membuat Youtube embed autoplay di mobile device, caranya cukup mudah. tinggal salin kode di bawah di website kalian. Script dibawah ini sudah sy modifikasi biar tidak menampilkan related video dari channel lain.


<div class="video-container">
    <div id="player"></div>

<script>
  var tag = document.createElement('script');
  tag.src = "https://www.youtube.com/iframe_api";
  var firstScriptTag = document.getElementsByTagName('script')[0];
  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  var player;
  function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
      width: '100%',
      videoId: 'id video kalian',
      playerVars: { 'autoplay': 1, 'playsinline': 1, 'controls':0, 'rel':0 },
      events: {
        'onReady': onPlayerReady
      }
    });
  }
  function onPlayerReady(event) {
     event.target.mute();
     event.target.playVideo();
  }
</script>
    </div>
</div>

<style type="text/css">
.video-container { position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden; }
.video-container iframe, .video-container object, .video-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
</style>



Top ad
Middle Ad 1
Parallax Ad
Middle Ad 2
Bottom Ad
Link copied to clipboard.