ended event videojs not working

前端 未结 5 1385

I would like to trigger a simple event when my video is finished. I\'ve placed this directly bellow my video tag.

     

        
相关标签:
5条回答
  • 2021-01-11 10:55

    "addEvent" and "removeEvent" were replaced by "on" and "off"

    try:

    this.on("ended", function(){ 
    
    0 讨论(0)
  • 2021-01-11 10:56

    On Stackoverflow i find one part of solution the otherpart find it from Lyn Headley top answer.

    <script type="text/javascript">
        //rename subtitle button
        videojs.addLanguage('de', {
            "captions off": "Untertitel aus",
        });
    
        videojs(document.querySelector('video') /* or selector string */, {
            techOrder: ['html5', 'flash'],
            controls: true,
            autoplay: false,
            preload: 'false',
            language: 'de',
            flash: {
                swf: 'video-js.swf'
            }
        }, function(){
            // Player (this) is initialized and ready.
            this.on('ended', function(){
                alert('ended');
            });
            this.on('firstplay', function(){
                alert('firstplay');
            });
        });
    </script>
    

    this will alert you on the end of video. place it under the code of your video and it should works.

    0 讨论(0)
  • 2021-01-11 11:02

    The ended event will not fire if end user intentionally seek the video to end keeping video as paused. I was able to get it work as:

      <script type="text/javascript">
          var player = videojs('my_video', {}, function() {});
          player.ready(function(){
            var duration_time =  Math.floor(this.duration());
            this.on('timeupdate', function() {
              var current_time =  Math.floor(this.currentTime());
              if ( current_time > 0 && ( current_time == duration_time ) ){
                $('#continue_button').removeAttr("disabled");
              }
            });
          });
      </script>

    0 讨论(0)
  • 2021-01-11 11:15

    2020 Updated answer:

    let player = videojs('video-player-id');
    
    player.on('ended', function() {
      this.dispose();
    });
    

    I think it's good to call dispose More on why over here

    0 讨论(0)
  • 2021-01-11 11:19

    For those who still have problems with ended events in some browsers you can resort to this fix:

        player.ready(function() {
                var myPlayer = this;
    
                playerInstance.on("timeupdate", function(event) { //chrome fix
                    if (event.currentTarget.currentTime == event.currentTarget.duration) {
                        console.log('video ended');
                    }
                });
        });
    
    0 讨论(0)
提交回复
热议问题