【问题标题】:How do I click a button to play iframe from google drive?如何单击按钮以从谷歌驱动器播放 iframe?
【发布时间】:2021-05-29 19:43:29
【问题描述】:

如何单击按钮以播放 Google Drive iframe,通过预览模式以正确的分辨率将其发送给用户?请使用 Javascript 或 Jquery,在此先感谢。

<button type="button">Play Video</button>

<iframe id="video" src="https://drive.google.com/file/d/1SRlH5RULz6sR3WPbTX4p9ZL7m2EtBjsj/preview?start=1"  allowfullscreen="allowfullscreen"></iframe>

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    根据这个Stack Overflow question,您可以将&lt;iframe&gt; 换成HTML5 &lt;video&gt;。 要播放视频,您需要添加一些 JavaScript。

    HTML:

    <video id="video">
        <source src="https://drive.google.com/uc?export=download&id=YourVideoIdHere" type='video/mp4'>
    </video>
    

    JavaScript:

    const myVideo = document.getElementById('video');
    const myButton = document.querySelector('button');
    myButton.addEventListener('click', function() {
        myVideo.play();
    });
    

    【讨论】:

    • 感谢您的回答,您可以通过预览模式来做吗,以正确的分辨率发送给用户?
    • 不幸的是,使用iframe 是不可能的。过去可以通过将 URL 更改为包含 autoplay=1start=1 来使用按钮播放,但谷歌在 2018 年左右更改了自动播放视频的政策时删除了此功能。唯一的另一种方法是上传不同分辨率的视频并添加更多来源。或者您可以使用其他视频托管服务,例如 Youtube 或 Vimeo。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-06
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    相关资源
    最近更新 更多