HTML5 视频 (videojs) 暂停() & play() 不起作用?
我有一个功能齐全的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法找到 videojs 函数参考,Google 完全误导了我。幸运的是,我找到了这个解决方案,并且效果非常好:
I wasn't able to find videojs function reference and Google was totally misleading. Luckily I found this solution, and it works perfect:
确保
canplay
事件在尝试调用.play()
之前已触发:当浏览器可以开始播放视频时,会触发
canplay
事件,但不保证可以播放视频完成。如果这不适合您的目的,您可以收听其他一些相关事件,例如loadeddata
和canplaythrough
。Make sure the
canplay
event has fired before trying to calling.play()
: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 asloadeddata
andcanplaythrough
.