Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an embedded Youtube video automatically start playing?

In my project, there is a video gallery module. In this module, there are two options: direct FLV uploading, and adding a video embed code from YouTube.

I am writing some embed code for a div element (actually, the embed code comes from database). I want to make this video begin playing automatically.

<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/zGPuazETKkI" frameborder="0" allowfullscreen></iframe> 

This is a sample embed code from YouTube. I want to make this video play automatically using JavaScript.

like image 831
Saritha Avatar asked Mar 18 '11 08:03

Saritha


People also ask

How do I make YouTube videos play automatically in HTML?

YouTube Autoplay + Mute You can let your video start playing automatically when a user visits the page, by adding autoplay=1 to the YouTube URL. However, automatically starting a video is annoying for your visitors! Note: Chromium browsers do not allow autoplay in most cases. However, muted autoplay is always allowed.

How do I automatically play video in iframe?

Allowing iframes to autoplay video content You should also note the need to use the allowfullscreen attribute in complement to the allow attribute in order to support browsers that do not support allow attribute. If you are using amp-iframe and autoplay you need to add allow="autoplay" to your amp-iframe element.

Why does my YouTube video not play automatically?

AutoPlay may not work on YouTube due to corrupt cache/data of the browser or corrupt installation of the YouTube mobile application. Moreover, an outdated browser or misconfiguration of your browser like DRM settings, etc. may also cause the error under discussion.


2 Answers

You have to use

<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/zGPuazETKkI?autoplay=1" frameborder="0" allowfullscreen></iframe> 

?autoplay=1

and not

&autoplay=1

its the first URL param so its added with a ?

like image 109
Alex Bailey Avatar answered Sep 29 '22 11:09

Alex Bailey


This works perfectly for me try this just put ?rel=0&autoplay=1 in the end of link

<iframe width="631" height="466" src="https://www.youtube.com/embed/UUdMixCYeTA?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe> 
like image 27
Jamil Ahmed Avatar answered Sep 29 '22 11:09

Jamil Ahmed