如果用户跳过了一些,我想测量视频播放期间跳过的时间。
使用 video.currentTime
首先它看起来很微不足道
Listen to seeking and get the currentTime A
Listen to seekend and get the currentTime B
B - A = Seeked Time
当我在 Chrome 中执行此操作时,结果为 0。这是为什么呢?如果您听 timeupdate TU,它会变得非常明显。简化序列:
Press Play
TU: 1
TU: 2
TU: 3 // now i use the mouse to seek forward to 19
TU: 19
//chrome & ff fire pause in between, ie not
Seek Start: 19
TU: 19
Seek End: 19
TU: 19
//chrome & ff fire play, ie not
TU: 20
...
我知道我可以玩脏并在某处保存 currentTime 但不是以可靠的方式;-)
使用 TimeRanges video.played
我可以使用 TimeRanges 来计算被搜索/跳过的时间量。但问题是:TimeRanges 以有序和规范化的形式作为列表出现。因此,如果用户向后跳,则 Ranges 会被合并和排序 => 对于准确跟踪来说不可靠。
有没有更简单的不太复杂的方法我只是没有看到?