The canplay/canplaythrough events for an HTML5 video are not called on Firefox. Why?

前端 未结 8 1304
自闭症患者
自闭症患者 2020-12-15 17:23

I\'m building a jQuery plugin for managing HTML5 videos. I\'m trying to capture the canplay and canplaythrough events. In Chrome, the event is fired without problem. In Fire

8条回答
  •  自闭症患者
    2020-12-15 18:00

    After 1.5 days of trying different approaches from here (in vanilla). The events "canplay" and "canplaythrough" with addEventListner don't work in Edge. They work fine in every other Browser. So I ended up with a check of "ready-state" with setTimout :-(. Not realy elegant, but it works for me.

    Controller.prototype.backGroundControl = function () {
    var vid = document.querySelector('#bgvid');
    var bgImg = document.querySelector('#bgimg');
    _this = this;
    
    if (vid.readyState === 4){
        bgImg.style.opacity = "0"
    } else{
        setTimeout(function(){
            _this.backGroundControl();
        },500)
    }  
    

    }

提交回复
热议问题