HTMLMediaElement持续时间不一致 [英] Inconsistent HTMLMediaElement duration

查看:105
本文介绍了HTMLMediaElement持续时间不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视频播放器出现问题,视频持续时间从 HTMLMediaElement.duration 不一致。我设置了以下侦听器来帮助说明:

I'm having an issue with my video player where the video duration returned from HTMLMediaElement.duration is not consistent. I set up the following listener to help illustrate:

video.addEventListener('timeupdate', function(e) {
    console.log('Duration: ' + video.duration);
    if ( video.currentTime === video.duration ) {
        console.log( video.currentTime + ' === ' + video.duration )
    }
});

当我一直寻找到视频结尾时,此事件返回不同的结果(更精确)值。我将在下面提供我的日志示例:

When I seek all the way to the end of the video, this event returns a different (more exact) value. I'll provide an example of my logs below:

Duration: NaN
Duration: 135.8357
Duration: 135.8357
Duration: 135.8357
Duration: 135.8357
Duration: 135.8357
Duration: 135.8357
...

..我要搜索视频的结尾。

...
Duration: 135.8357
135.8357 === 135.8357
Duration: 135.952833

我一直寻找到视频结尾,当前时间等于持续时间,然后持续时间更新为另一个时间。一直搜索到视频结尾不会触发 end 事件(除非视频恢复并达到 135.952833 的新终点) code>)。

I seek all the way to the end of the video, the current time is equal to the duration, and then the duration updates to a different time. Seeking all the way to the end of the video does not fire the ended event (unless the video resumes and hits the new end point of 135.952833).

是否有人对此问题有任何见解或对可能解决方案的想法?

Does anyone have any insight into this issue or thoughts on a possible solution?

推荐答案

我遇到了完全相同的问题,但有音频元素。当搜索音频的终点时,会不断触发 durationchange 事件, audio.duration 会持续变化几秒钟

I had exactly the same issue but with an audio element. When seeking to the end point of the audio, durationchange event was constantly triggered, audio.duration keeps changing for several seconds.

原来是音频源的问题。这是有问题的音频的提琴手: https://jsfiddle.net/jessuni/kxcmye8z/42/
您是否尝试过另一个视频源并重现此问题?

Turned out to be the audio source's problem. Here's a fiddle of the problematic audio: https://jsfiddle.net/jessuni/kxcmye8z/42/ Have you tried another video source and reproduce the issue?

这篇关于HTMLMediaElement持续时间不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆