Answer the question
In order to leave comments, you need to log in
Autoplay video in carousel?
Good day, such a problem, I need active videos in the carousel (I use OWL) to automatically start playing. Initially, I just added the autoplay value to the iframe via js:
//циклом обхожу все irame и передаю их в функцию которая добавляет нужные атрибуты:
let oldLink= video.getAttribute('src');
let newLink=oldLink+'?rel=0&modestbranding=1&autohide=1&mute=1&autoplay=1';
video.setAttribute('src', newLink);
video.setAttribute('allow','accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture');
<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', {
width: '100%',
videoId: '1w1212w12w12w',
playerVars: { 'autoplay': 1, 'playsinline': 1 },
events: {
'onReady': onPlayerReady
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.mute();
event.target.playVideo();
}
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question