javascript - 如果视频正在加载(缓冲),则显示带有加载 GIF 图像的 HTML5 视频
问题描述
所以 HTML5 视频没有控件。基本上我想显示一个加载 gif,仅在视频加载(缓冲和暂停)时显示在视频上
<video id="myvideo" width="100%"><source src="video/Good.mp4" type="video/mp4"><source src="movie.html" type="video/ogg"></video>
解决方案
如何使用内置的浏览器动画而不是 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>
也许你可以用whichontimeupdate
代替onplaying
which 会连续开火。至于延迟时间实际上不是 1 秒而是 4 秒——对我来说——是最好的。
推荐阅读
- angular - Angular 组件 - 在运行时创建或使用数据参数静态创建
- oauth - 社交 oauth 如何真正发挥作用?
- node.js - 运行 2 个重复的异步函数,而不在 await 上暂停另一个
- sql - CASE 错误地返回 true
- angularjs - 升级以在 AngularJS 的指令中使用 $onInit
- udp - Google 计算引擎连接到本地 UDP 端口
- selenium - 如何在电子邮件(Outlook)正文中为测试执行摘要生成 HTML 表
- c# - 我们可以保留从.NET 创建的## 表,直到我从另一个过程执行我的代码?
- sql - 编写一个循环,引入两种不同的日期格式
- python - 如何在会话 SQLAlchemy 中获取对象的父对象