Videojs TypeError: this.addEvent is not a function

2019-05-16 16:27发布

问题:

Really don't know what's wrong with my code! I'm tryng to attach the end event to my player by i get this error in my firefox console:

"TypeError: this.addEvent is not a function"

I tried in so many way, but coudnt solve this problem!

<!DOCTYPE html>
<html>
<head>
  <link href="video-js.css" rel="stylesheet" type="text/css">
  <script src="video.js"></script>
  <script>_V_.options.flash.swf = "video-js.swf";</script>
</head>
<body>
  <video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="400" height="500" data-setup='{}'
      poster="http://video-js.zencoder.com/oceans-clip.png">
    <source src="http://video-js.zencoder.com/oceans-clip.mp4" type='video/mp4' />
    <source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm' />
    <source src="http://video-js.zencoder.com/oceans-clip.ogv" type='video/ogg' />
    <track kind="captions" src="demo.captions.vtt" srclang="en" label="English" />
  </video>
<script>
var myPlayer = videojs("example_video_1");

videojs("example_video_1").ready(function(){
    var myPlayer = this;

    var videoEnd = function(){
      console.log('ended')
    };

    myPlayer.addEvent("ended", videoEnd);

});
</script>
</body>
</html>

Can u help me please? thanks a lot

回答1:

video.js has recently been updated to version 4 and some things in the API have changed. You'll need to use myPlayer.on("ended", videoEnd);

API docs: https://github.com/videojs/video.js/blob/master/docs/api/vjs.Player.md



标签: video.js