【问题标题】:Showing HTML5 Video with a loading GIF image if the video is loading (buffering)如果视频正在加载(缓冲),则显示带有加载 GIF 图像的 HTML5 视频
【发布时间】:2019-02-10 00:48:00
【问题描述】:

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

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

【问题讨论】:

标签: javascript jquery css html


【解决方案1】:

如何使用内置的浏览器动画而不是 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 秒——对我来说——是最好的。

【讨论】:

    猜你喜欢
    • 2016-04-21
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-06
    • 1970-01-01
    相关资源
    最近更新 更多