javascript video.js 结束事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14398537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 21:31:31  来源:igfitidea点击:

video.js ended event

javascriptvideo.js

提问by user1990139

Why this throws up this error:

为什么会引发此错误:

The element or ID supplied is not valid. (VideoJS)

提供的元素或 ID 无效。(VideoJS)

I know it may be obvious but there's the code:

我知道这可能很明显,但有代码:

<script type="text/javascript">
 var videoPlayer = _V_("example_video_1", {}, function(){
this.addEvent("ended", function(){ 
   alert('Here I am');
  });
});        
</script>

and video ID set via PHP

和通过 PHP 设置的视频 ID

<?PHP
  echo "<video id=\"example_video_1\" class=\"video-js vjs-default-skin\"  controls width=\"".$vid_h."\" height=\"".$vid_w."\" autoplay preload=\"auto\" data-setup='{}'>";
?>

回答by misterben

Make sure your script is after the video element it references. Otherwise your get "the element or ID supplied is not valid" because it doesn't exist at the point the script executes.

确保您的脚本在它引用的视频元素之后。否则你会得到“提供的元素或 ID 无效”,因为它在脚本执行时不存在。

e.g.

例如

<!DOCTYPE html>
<html>
<head>
  <link href="http://vjs.zencdn.net/c/video-js.css" rel="stylesheet">
  <script src="http://vjs.zencdn.net/c/video.js"></script>
</head>
<body>
  <video id="example_video_1" class="video-js vjs-default-skin" controls preload="auto" width="360" height="202" autoplay data-setup="{}">
    <source src="http://example.com/video.mp4" type='video/mp4'>
  </video>
  <script type="text/javascript">
    var videoPlayer = _V_("example_video_1", {}, function(){
      this.addEvent("ended", function(){ 
        alert('Here I am');
      });
    });       
  </script>
</body>
</html>