How to disable auto-play for local video in iframe

后端 未结 8 970
我在风中等你
我在风中等你 2020-12-29 21:08

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




        
相关标签:
8条回答
  • 2020-12-29 21:48

    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").

    0 讨论(0)
  • 2020-12-29 21:49
    <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

    0 讨论(0)
  • 2020-12-29 21:52

    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>
    
    0 讨论(0)
  • 2020-12-29 21:53

    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>
    
    0 讨论(0)
  • 2020-12-29 21:59

    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>
    
    0 讨论(0)
  • 2020-12-29 22:01

    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.

    0 讨论(0)
提交回复
热议问题