html5 video preload

前端 未结 2 2098
粉色の甜心
粉色の甜心 2021-02-05 13:41

Is it possible to preload an html video? Note: the tag is created dynamicly later.

Currently I can do this with images by creating a hidden div and putting all the ima

2条回答
  •  走了就别回头了
    2021-02-05 14:09

    I had a similar problem in IE, some of the videos are display:none, and when I show them IE doesn't show first frame...

    I used the following code to solve it, when I show the hidden videos I call preloadAllVisible()

    var preloadAllVisible = function() {
        $("video:visible").each(preload);
    }
    var preload = function(key, vid) {
        vid.play(); 
        setTimeout("pausevid("+key+")",100);
    }
    
    var pausevid = function(key) {
        vid =$("video:visible")[key];
        vid.pause();
        vid.currentTime = 0;
    }
    

提交回复
热议问题