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

前端 未结 8 1303
自闭症患者
自闭症患者 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:09

    I do also think this is a race condition. The way I got around it is as follows:

    In the HTML of the video element add the attribute preload="metadata" - to just preload the video metadata. So:

    <video id="myVideo" width="640" height="480" preload="metadata" />
    

    Next, inside the JS:

    var $vid = $("#myVideo");
    $vid.bind("canplaythrough", console.log("can play through full video"));
    $vid.get(0).load();
    

    This logged the message for me in Chrome - haven't tested elsewhere.

    0 讨论(0)
  • 2020-12-15 18:10

    In my case, this was determined by the preload attribute specified for the element. I did not have it specified at all, so different browsers were choosing to do different things.

    Once I specified preload="auto", the on("canplay") event handler worked fine/as expected.

    0 讨论(0)
提交回复
热议问题