Detect when video is buffering, if so display gif

后端 未结 2 863
执念已碎
执念已碎 2021-02-09 18:47

I\'am wondering if there\'s a way to display a .gif while the video is buffering.

I\'am using the HTML5 Video Tag, within this is there a way to detect when a video is b

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-09 19:40

    You can use the onwaiting event handler on the video element to show an image when the video starts buffering and the onplaying event handler when the video resumes (compare video element events)

    video.onwaiting = function(){
        showPlaceholder(placeholder, this);
    };
    video.onplaying = function(){
        hidePlaceholder(placeholder, this);
    };
    

    I created a little fiddle where you can get an idea of how to do it (Note that i simulated the buffering after 1 second by code).

提交回复
热议问题