HTML5 视频 (videojs) 暂停() & play() 不起作用?

发布于 2024-12-24 19:23:39 字数 499 浏览 2 评论 0原文

我有一个功能齐全的 HTML5 视频,它的 ID 是“#html5-video-7345”。

我正在尝试使用 jQuery 来控制它,但我不知道如何控制。

注意:我不需要自动播放,这只是我需要的简化版本:

 jQuery(document).ready(function(){
    alert('test1');
    jQuery('#html5-video-7345').player.play();
    alert('test2');
 });

警报“test1”两次。

jQuery('#html5-video-7345')[0].player.play()jQuery('#html5-video-7345')[0] 也会发生同样的情况。播放()。

怎么了?如何使用 jQuery/JS stop() / play() HTML5 视频?

I have a fully functional HTML5 video, it's ID is "#html5-video-7345".

I'm trying to control it using jQuery but I don't know how.

NOTE: I don't need an autoplay, this is just simplified version of what I need:

 jQuery(document).ready(function(){
    alert('test1');
    jQuery('#html5-video-7345').player.play();
    alert('test2');
 });

Alerts "test1" twice.

The same happens with jQuery('#html5-video-7345')[0].player.play() or jQuery('#html5-video-7345')[0].play().

What's wrong? How to stop() / play() HTML5 videos using jQuery/JS?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戴着白色围巾的女孩 2024-12-31 19:23:39

我无法找到 videojs 函数参考,Google 完全误导了我。幸运的是,我找到了这个解决方案,并且效果非常好:

jQuery('#html5-video-7345').player.play(); //wrong
jQuery('#html5-video-7345').player().play(); //correct

I wasn't able to find videojs function reference and Google was totally misleading. Luckily I found this solution, and it works perfect:

jQuery('#html5-video-7345').player.play(); //wrong
jQuery('#html5-video-7345').player().play(); //correct
初吻给了烟 2024-12-31 19:23:39

确保 canplay 事件在尝试调用 .play() 之前已触发:

jQuery('#html5-video-7345').bind("canplay", function() {
    this.play(); // Should start video
});

当浏览器可以开始播放视频时,会触发 canplay 事件,但不保证可以播放视频完成。如果这不适合您的目的,您可以收听其他一些相关事件,例如 loadeddatacanplaythrough

Make sure the canplay event has fired before trying to calling .play():

jQuery('#html5-video-7345').bind("canplay", function() {
    this.play(); // Should start video
});

The canplay event is fired when the browser can start playing the video, but it doesn't guarantee that it can play the video to completion. If that doesn't suite your purposes, there are a couple of other related events that you can listen to such as loadeddata and canplaythrough.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文