javascript 使html5视频在结束时进入第一帧?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8132890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 02:24:50  来源:igfitidea点击:

make html5 video go to first frame when it ends?

javascriptjqueryhtml5-video

提问by CCrawler

I have a simple video html5 tag, bound to an "ended" event:

我有一个简单的视频 html5 标签,绑定到“结束”事件:

$('#video').show().trigger("play").bind('ended', function () { 
//code
}

Since I'm "showing" and "hiding" this through a button click, I wanted to make it return to the first frame on that last function, so it would start from the beginning the next time it appears (right now it starts from the ending, and it causes a nasty flicker when it goes from the last to the first frame).

由于我通过单击按钮“显示”和“隐藏”它,我想让它返回到最后一个函数的第一帧,所以它会在下次出现时从头开始(现在它从结尾,当它从最后一帧转到第一帧时会导致令人讨厌的闪烁)。

Is that possible with jQuery?

用 jQuery 可以吗?

Thanks in advance!

提前致谢!

回答by Niels

You can use something like

你可以使用类似的东西

$('#video').show().trigger("play").bind('ended', function () { 
    this.currentTime = 0;
}

You can only set the currentTime if the loadedmetadata event has passed.

如果loadedmetadata 事件已经过去,您只能设置currentTime。

回答by IconMatrix

This goes in the head:

这是在头脑中:

<script>
function Reset() { document.getElementById('MyVideo').load(); }
</script>

This goes in the video tag:

这在视频标签中:

<video ID="MyVideo" onended="Reset()" [plus your other parameters] >