[英]HTML5 video Uncaught TypeError: .play is not a function
I have a problem with video autoplay after buttonc click which opens foundation modal with video to be played.我在单击 buttonc 后视频自动播放有问题,这会打开要播放视频的基础模式。 When i click on button to open modal with video, it opens but video do not start playing.当我点击按钮打开带有视频的模式时,它会打开但视频没有开始播放。
In console i get Uncaught TypeError: .play is not a function error在控制台中,我得到 Uncaught TypeError: .play is not a function error
Opening modal button:打开模态按钮:
<div data-open="movieModal" id="movieModalOpenMedium">Open</div>
Video modal:视频模态:
<div class="reveal full" id="movieModal" data-reveal data-reset-on-close="true">
<video id="company-movie" controls>
<source src="/video/movie.mp4" type="video/mp4">
</video>
And script looks like:脚本看起来像:
$(document).ready(function(){
// var movie = document.getElementById('company-movie');
var movie = $('#company-movie').get(0);
$('#movieModalOpenMedium').click(function(){
movie.play();
})
}) })
#company-movie element is seen correctly in DOM however i cannot play it in any way. #company-movie元素在 DOM 中正确显示,但我无法以任何方式播放它。
I have tried with:我试过:
$('#company-movie').play() - JQuery Object does not have play() method so for sure it will not work $('#company-movie').play() - JQuery 对象没有 play() 方法所以肯定它不会工作
$('#company-movie').get(0).play(); $('#company-movie').get(0).play();
but neither of these ways works.但这些方法都不起作用。
I was also trying to do this without jQuery this way:我也试图通过这种方式在没有 jQuery 的情况下做到这一点:
$(document).ready(function(){
var movie = document.getElementById('company-movie');
document.getElementById("movieModalOpenMedium").addEventListener("click", function(){
movie.play();
});
}) })
but it also does not work.但它也不起作用。
I would be grateful for any help with it.我将不胜感激。
Try $('#company-movie')[0].play();
试试$('#company-movie')[0].play();
or $('#company-movie').get(0).play();
或$('#company-movie').get(0).play();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.