Play embedded video after x seconds

Degen

Elite Member
Joined
Apr 9, 2016
Messages
2,604
Reaction score
2,899
Does anyone know how to autoplay an embedded youtube video after x seconds on a wordpress site?
 
according to iframe api doc its possible but you have to manually add the code to every video for delay.
jQuery:
HTML:
loadVideoById({'videoId': 'bHQqvYy5KYo',
               'startSeconds': 5,
               'endSeconds': 60,
               'suggestedQuality': 'large'});
 
according to iframe api doc its possible but you have to manually add the code to every video for delay.
jQuery:
HTML:
loadVideoById({'videoId': 'bHQqvYy5KYo',
               'startSeconds': 5,
               'endSeconds': 60,
               'suggestedQuality': 'large'});
not working, have found something else that does work, only problem is that it opens a notification before auto playing. (which also doesn't count the views)
 
You can try this:

Code:
setTimeout(function() {
  let url = $('iframe').attr('src')
  url = url+'?autoplay=1';
  $('iframe').attr('src', url);
}, 2000); // 2000 = 2s, 10s= 10000

This will affect any iframe on the page, to change that use id attribute with the iframe

Code:
 <iframe id="youtubeiframe"></iframe>

and use this instead of the above code:

Code:
setTimeout(function() {
  let url = $('#youtubeiframe').attr('src')
  url = url+'?autoplay=1';
  $('#youtubeiframe').attr('src', url);
}, 2000); // 2000 = 2s, 10s= 10000
 
Back
Top