【问题标题】:Auto pause in embeded video嵌入视频中的自动暂停
【发布时间】:2021-12-30 12:10:00
【问题描述】:

我想要一个在设定时间自动暂停的视频,然后用户必须按下播放按钮。我已经设法在嵌入的 YouTube 上播放并停止播放,但一旦停止,我就无法播放。理想情况下希望能够在 Vimeo 中执行此操作。任何帮助都会很棒。

【问题讨论】:

    标签: html youtube vimeo


    【解决方案1】:

    你可以设置一个“睡眠”定时器,然后使用暂停命令,如下所示:

    <!DOCTYPE html> 
    <html> 
    <body> 
    
    <button onclick="playVid()" type="button">Play Video</button>
    <button onclick="pauseVid()" type="button">Pause Video</button><br> 
    
    <video id="myVideo" width="320" height="176">
      <source src="mov_bbb.mp4" type="video/mp4">
      <source src="mov_bbb.ogg" type="video/ogg">
      Your browser does not support HTML5 video.
    </video>
    
    <script> 
    var vid = document.getElementById("myVideo"); 
    
    async function playVid() { 
      vid.play();
      // Sleep timer with 2000s
      await new Promise(resolve => setTimeout(resolve, 2000));
      // After this, pause
      vid.pause();
    } 
    
    function pauseVid() { 
      vid.pause(); 
    } 
    </script> 
    
    <p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>
    
    </body> 
    </html>
    

    参考:https://www.w3schools.com/tags/av_met_pause.asp

    【讨论】:

    • 您好,谢谢,您有没有机会给我一个示例,说明如何使用以下嵌入代码执行此操作,其中视频中有 2 个随机暂停。
    猜你喜欢
    • 2019-06-23
    • 2014-11-06
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    • 2015-06-27
    • 1970-01-01
    • 2014-02-21
    • 1970-01-01
    相关资源
    最近更新 更多