javascript - HTML 视频 currentTime 未正确设置
问题描述
我有一个视频被用作移动设备的背景,以显示手机旋转时的反应动画(有点),但是当旋转需要它从头到尾循环或从头到尾循环时,它不会循环而且我不知道为什么它试图设置的值应该有效。
这是订阅陀螺仪并用一些数学更新角度的函数
this.gyroscope.watch(this.options)
.subscribe((orientation: GyroscopeOrientation) => {
// need delta time to correctly calculate angle per update
this.time.now = new Date().getTime();
this.time.delta = this.time.now - this.time.last;
if (this.videoLoaded) {
// convert radians/sec to degree/sec and times by deltaTime
const degree = 180 / Math.PI * orientation.z;
this.targetAngle -= (this.time.delta / 1000) * degree;
// lerp target angle no clipping applied
this.angle = (1 - .1) * this.angle + .1 * this.targetAngle;
// convert lerped angle into clipped 0-360
let displayAngle = this.angle % 360;
if (displayAngle < 0) { displayAngle = 360 + displayAngle; }
// convert angle to time of video round to tenths dec
this.frame = Math.round((displayAngle * this.axeVideo.duration / 360) * 10) / 10;
// set video time
this.axeVideo.currentTime = this.frame;
} else {
// clear angle as gyro spits out large values at first
this.angle = this.targetAngle = 0;
}
// update last time for deltaTime calc
this.time.last = this.time.now;
});
这都是正确的数学并且在逻辑上有效但是在测试视频时无论手机旋转多少次都会锁定并“解锁”它我必须将手机旋转回相同的量。
问题记录的屏幕截图有点滞后,但通常超级流畅(因此我使用此解决方案)。
解决方案
它ion-range
上面有 [(ngModel)] 覆盖了设定的时间。
推荐阅读
- .net - AWS Glacier 的 Django 与 .Net
- python - 将小于 2 位的数值的前导零添加到现有数据框列(python)
- html - 如何在 select2 框上应用边框半径?
- sql - 在多个日期之间的天数上生成行,计算每个日期之间的天数,以及第一个和最后一个日期
- javascript - 如何在 JavaScript 中单击带有扩展名的按钮
- list - Flutter Firebase where query arrayContains in List
- r - 如何读入大量与个人 ID 号码匹配的 csvs R
- docker - 如何使用 bazel rules_docker 中的 container_image 或 container_layer 为 empty_dir 定义所有者?
- sql - 如何将两个表连接在一起(一对多关系),但只从第二个表中选择第三个匹配项?
- python - 使用字典获取拼字游戏单词的总分