如果视频正在加载(缓冲),则显示HTML5视频以及正在加载的GIF图像

时间:2019-02-10 00:48:01

标签: javascript jquery html css html5

因此HTML5视频没有控件。基本上,我想显示一个加载gif,仅当视频正在加载(缓冲和暂停)时才在视频上显示

<video id="myvideo" width="100%"><source src="video/Good.mp4" type="video/mp4"><source src="movie.html" type="video/ogg"></video> 

1 个答案:

答案 0 :(得分:0)

如何使用内置的浏览器动画而不是gif。 您所要做的就是将控件设置为TRUE,然后根据缓冲状态回到FALSE。 对我来说,最佳做法是这样,

<video src="myVideo.fileExtension" onplaying="hideControls(this)" onwaiting="showControls(this)" preload="auto" poster="myAnimatedWebpOrGifThatSaysVideoIsNotYetReady.fileExtension">No video support?</video>

<script type="text/javascript">
//We hide the video control buttons and the playhead when the video is playing and enjoyed by the viewer
function hideControls(event){ event.controls=false; }
//If the video has to pause and wait for data from the server we let controls be seen if the user hovers or taps on the video. As a bonus this also makes the built-in loading animation of the browser appear e.g. the rotating circular shape and we give it a little delay (like 1 sec) because I would say it looks and feels better.
function showControls(event){ setTimeout(function(){ event.controls=true; },1000); }
</script>

也许您可以使用ontimeupdate而不是onplaying来连续触发。 至于延迟时间,实际上对我来说不是1而是4秒。