[html] How to disable auto-play for local video in iframe

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"

This question is related to html iframe video autoplay

The answer is


Just replace

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

by

<video src="videos/example.mp4" controls></video>

Here is an example using bootstrap 4:

 <div class="embed-responsive embed-responsive-4by3">
      <video src="videos/example.mp4" controls></video>
 </div>

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>

I've tried all the possible solutions but nothing worked for local video bindings. I believe best solution would be to fix using jQuery if you still wants to use iframes.

$(document).ready(function () {
    var ownVideos = $("iframe");
    $.each(ownVideos, function (i, video) {                
        var frameContent = $(video).contents().find('body').html();
        if (frameContent) {
            $(video).contents().find('body').html(frameContent.replace("autoplay", ""));
        }
    });
});

Note: It'll find all the iframes on document ready and loop through each iframe contents and replace/remove autoplay attribute. This solution can be use anywhere in your project. If you would like to do for specific element then use the code under $.each function and replace $(video) with your iframe element id like $("#myIFrameId").


You can set the source of the player as blank string on loading the page, in this way you don't have to switch to video tag.

var player = document.getElementById("video-player");
player.src = "";

When you want to play a video, just change its src attribute, for example:

function play(source){
   player.src = source;
}

Replace the iframe for this:

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

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>

<iframe width="420" height="315"
    src="https://www.youtube.com/embed/aNOgO7aNslo?rel=0">
</iframe>

You're supposed to put the characters ?rel=0 after the YouTube video unique link and before the quotations. it worked for me


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.


Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to iframe

Getting all files in directory with ajax YouTube Autoplay not working Inserting the iframe into react component How to disable auto-play for local video in iframe iframe refuses to display iFrame onload JavaScript event YouTube iframe embed - full screen Change New Google Recaptcha (v2) Width load iframe in bootstrap modal Responsive iframe using Bootstrap

Examples related to video

How to handle "Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first." on Desktop with Chrome 66? How to make a movie out of images in python HTML5 Video autoplay on iPhone How do we download a blob url video Twitter - How to embed native video from someone else's tweet into a New Tweet or a DM How to embed new Youtube's live video permanent URL? How to disable auto-play for local video in iframe Writing an mp4 video using python opencv How to extract 1 screenshot for a video with ffmpeg at a given time? Bootstrap 3 - Responsive mp4-video

Examples related to autoplay

HTML5 Video autoplay on iPhone How to disable auto-play for local video in iframe Autoplay an audio with HTML5 embed tag while the player is invisible Disable html5 video autoplay HTML5 Video Autoplay not working correctly Very Simple Image Slider/Slideshow with left and right button. No autoplay