Autoplay of YouTube Iframe Player with firefox and chrome

YouTube Embedded Video


1st Example:  

<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', {
        videoId: 'xxxxx',
        playerVars: {  
            'autoplay': 1,
            'rel': 0,
            'showinfo': 0,
            'modestbranding': 1,
            'playsinline': 1,
            'showinfo': 0,
            'rel': 0,
            'controls': 0,
            'color':'white',
            'loop': 1,
            'mute':1,
            // 'origin': 'http://t10kwithshahin.blogspot.com/'
        },
        events: {
        'onReady': onPlayerReady,
        // 'onStateChange': onPlayerStateChange
        }
    });

    }

    function onPlayerReady(event) {
        player.playVideo();
        player.mute();
    }

var done = false;
    function onPlayerStateChange(event) {
    if (event.data == YT.PlayerState.PLAYING && !done) {
        setTimeout(stopVideo, 6000);
        done = true;
    }
    }
    function stopVideo() {
        player.stopVideo();
    }
</script>


Other example:

<div id="video" class="hidden-xs loaded">
<iframe class="ytplayer-player" style="width: 1519px; height: 855px; left: 0px; top: -281px;" allowfullscreen="1" allow="autoplay" title="YouTube video player" src="https://www.youtube.com/embed/3kLYx2BAUJ4?iv_load_policy=3&modestbranding=0&autoplay=1&controls=0&rel=0&showinfo=0&wmode=opaque&branding=0&autohide=0&loop=1&rel=0&enablejsapi=1&origin=https%3A%2F%2Fhub.youth.gov.ae&widgetid=1&mute=1" width="1519" height="855" frameborder="0"></iframe>
</div>

Autoplay of YouTube Iframe Player with firefox and chrome Autoplay of YouTube Iframe Player with firefox and chrome Reviewed by TechTubeHQ on February 22, 2022 Rating: 5

No comments:

Powered by Blogger.