javascript - HTML 视频缓冲冻结
问题描述
我正在制作自定义视频控件,我有一个@progress
事件用于跟踪视频的缓冲量并更新进度条的宽度div
:
<video @progress="videoBuffer($event)">
videoBuffer(e) {
if (e.target.buffered.length === 1)
// videoBuffered passed as props to the controls
this.videoBuffered = (e.target.buffered.end(0) / e.target.duration) * 100;
},
<div
class="dk__video-buffered"
:style="{ maxWidth: videoBuffered + '%' }"
></div>
如果您从头到尾播放视频并且不点击超出缓冲范围,这可以正常工作:
这也适用于用拇指擦洗。
但是,如果您单击超出缓冲范围,它会冻结:
点击事件的代码:
<div
class="dk__video-track-container"
@click="trackTime($event)"
>
<div class="dk__video-track">
<div
class="dk__video-played"
:style="{ width: playedWidth + '%' }"
></div>
<div
class="dk__video-buffered"
:style="{ maxWidth: videoBuffered + '%' }"
></div>
</div>
</div>
trackTime(e) {
// Set the videos time on click
this.video.currentTime =
(e.offsetX / e.target.offsetParent.offsetWidth) * this.videoDuration;
},
起初我认为这将是 Vue 的反应性问题,因为我通过 props 传递缓冲区数据,但是,当我console.log(e.target.buffered.end(0))
看到数据本身冻结在单击时的任何位置时。
有谁知道为什么会这样或我该如何解决?
解决方案
推荐阅读
- php - Css 更改锚文本不适用于 PHP/Laravel
- javascript - 将 XML 转换为 JSON 时如何解决编码问题?
- svelte - 故事书黑暗模式导致黑屏
- mongodb - 使用spring boot将FTP服务器中检索到的文件上传到mongodb集合
- npm - 哟生成器代码未安装在 Linux PC 上
- excel - VBA代码删除工作表中的额外行,数千行显着减慢
- string - 程序不接受第一个输入?
- node.js - 如果在 express-validator 中使用 .if(myCondition).optional() 可能满足条件,则使字段可选?
- java - 依赖 jar 中文件的 Maven 路径
- powerbi - 从 Power BI 中的视觉对象取消数据透视表