我想从视频链接中获得持续时间

发布于 2025-02-06 05:27:28 字数 854 浏览 1 评论 0原文

我想从视频链接中获得持续时间。它可能是YouTube视频以及另一个视频链接。但是YouTube视频正在IFRAME中播放,而另一个则在视频标签中工作。但是我只能从视频标签中获取持续时间。如何从iframe和视频中获得视频持续时间。

<button onclick="myFunction()" type="button">Get video length</button><br>

<video id="myVideo" width="320" height="176" controls>
    <source src="https://dev.theappkit.co.uk/stylco/public/images/hair_styles/0_427_serena_grant_1619797376.mp4"
        type="video/mp4">
    Your browser does not support HTML5 video.
</video>

<script>
    var vid = document.getElementById("myVideo");

    function myFunction() {
        alert(vid.duration);
    } 
</script>

<script type='text/javascript'>
    document.getElementById('myVideo').addEventListener('ended', myHandler, false);
    function myHandler(e) {
        alert("ended");
    }
</script>

I want to get duration from video links . it could be a youtube video as well as another video link. But youtube videos are playing in iframes and another are working in video tag. but im only able to fetch duration from video tag. How could get video duration from both iframe and video.

<button onclick="myFunction()" type="button">Get video length</button><br>

<video id="myVideo" width="320" height="176" controls>
    <source src="https://dev.theappkit.co.uk/stylco/public/images/hair_styles/0_427_serena_grant_1619797376.mp4"
        type="video/mp4">
    Your browser does not support HTML5 video.
</video>

<script>
    var vid = document.getElementById("myVideo");

    function myFunction() {
        alert(vid.duration);
    } 
</script>

<script type='text/javascript'>
    document.getElementById('myVideo').addEventListener('ended', myHandler, false);
    function myHandler(e) {
        alert("ended");
    }
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文