最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - video.js ended event - Stack Overflow

programmeradmin1浏览0评论

Why this throws up this error:

The element or ID supplied is not valid. (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
  echo "<video id=\"example_video_1\" class=\"video-js vjs-default-skin\"  controls width=\"".$vid_h."\" height=\"".$vid_w."\" autoplay preload=\"auto\" data-setup='{}'>";
?>

Why this throws up this error:

The element or ID supplied is not valid. (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
  echo "<video id=\"example_video_1\" class=\"video-js vjs-default-skin\"  controls width=\"".$vid_h."\" height=\"".$vid_w."\" autoplay preload=\"auto\" data-setup='{}'>";
?>
Share Improve this question edited Jan 19, 2013 at 12:26 ЯegDwight 25.3k10 gold badges47 silver badges52 bronze badges asked Jan 18, 2013 at 12:01 user1990139user1990139 191 gold badge1 silver badge4 bronze badges 6
  • is this the library used? github./zencoder/video-js – Janus Troelsen Commented Jan 18, 2013 at 12:03
  • Please show the generated HTML, not the PHP code. – JJJ Commented Jan 18, 2013 at 12:04
  • No - good point!generated - video id="example_video_1" class="video-js vjs-default-skin" controls width="240" height="320" autoplay preload="auto" data-setup='{}'> – user1990139 Commented Jan 18, 2013 at 12:46
  • No - I only have <link href="video-js.css" rel="stylesheet"/> <script src="video.js"></script>. PLEASE can you give me correct versions. – user1990139 Commented Jan 18, 2013 at 13:01
  • It's impossible to help if we don't know what library you're using. "video.js" couldn't be anything. – JJJ Commented Jan 19, 2013 at 11:31
 |  Show 1 more ment

1 Answer 1

Reset to default 5

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.

e.g.

<!DOCTYPE html>
<html>
<head>
  <link href="http://vjs.zencdn/c/video-js.css" rel="stylesheet">
  <script src="http://vjs.zencdn/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./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>
发布评论

评论列表(0)

  1. 暂无评论