How to disable auto-play for local video in iframe

167,089

Solution 1

If you are using HTML5, using the Video tag is suitable for this purpose.

You can use the Video Tag this way for no autoplay:

<video width="320" height="240" controls>
    <source src="videos/example.mp4" type="video/mp4">
</video>

To enable auto-play,

<video width="320" height="240" controls autoplay>
    <source src="videos/example.mp4" type="video/mp4">
</video>

Solution 2

Try This Code for disable auto play video.

Its Working . Please Vote if your are done with this

<div class="embed-responsive embed-responsive-16by9">
    <video controls="true" class="embed-responsive-item">
      <source src="example.mp4" type="video/mp4" />
    </video>
</div>

Solution 3

if you still need to use an iframe, add a sandbox

<iframe width="465" height="315" src="videos/example.mp4" sandbox></iframe>

Solution 4

Replace the iframe for this:

<video class="video-fluid z-depth-1" loop controls muted>
  <source src="videos/example.mp4" type="video/mp4" />
</video>

Solution 5

What do you think about video tag ? If you don't have to use iframe tag you can use video tag instead.

<video width="500" height="345" src="hey.mp4"  />

You should not use autoplay attribute in your video tag to disable autoplay.

Share:
167,089
Taleb
Author by

Taleb

Updated on August 20, 2021

Comments

  • Taleb
    Taleb over 2 years

    How to disable auto-play for video when src is from my local pc?

    <iframe width="465" height="315" src="videos/example.mp4"></iframe>
    

    I have tried the following, but it doesn't work:

    • src="videos/example.mp4?autoplay=0"
    • src="videos/example.mp4?autoplay=false"
    • src="videos/example.mp4?autostart=0"
    • src="videos/example.mp4?autostart=false"
  • Abhishek
    Abhishek over 8 years
    Any explanation for down voting my answer?
  • huysentruitw
    huysentruitw over 8 years
    Why would that first part ever work? I like your video-tag suggestion though.
  • Taleb
    Taleb over 8 years
    thank you for usefull answer, how could i display first frame of video, it looks now like play button in the middle with grey background
  • Abhishek
    Abhishek over 8 years
    @Taleb: I am using Google Chrome and it shows the first frame for me with the player control hovering below the video. Which Browser are you using? Check this link once. w3schools.com/tags/tryit.asp?filename=tryhtml5_video_autopla‌​y
  • t_b_b
    t_b_b over 6 years
    He wrote "local file." What has YouTube got to do with it?
  • Harshit Shah
    Harshit Shah over 4 years
    @Taleb, you can set a poster frame on the <video> tag
  • Yunnosch
    Yunnosch almost 3 years
    While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.
  • www-0av-Com
    www-0av-Com over 2 years
    Although you should have explained "add sandbox attribute", this is the correct answer to the question along with DAYdenisov's answer earlier. All the <Video> tag answers are not technically correct because they suggest you change your code completely.