如何停止播放< video>元素并将其恢复到原始状态? [英] How to stop playing a <video> element and return it back to its original state?

查看:783
本文介绍了如何停止播放< video>元素并将其恢复到原始状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将正在播放或暂停的视频重置为未播放的原始状态?我知道你可以暂停视频,但我真正想要的是让视频恢复到初始状态。这意味着如果指定它将显示海报图像,并且如果用户再次点击播放将从头开始。

I was wondering how I could go about resetting a video that was playing or paused to its original state where it isn't playing? I know you can pause the video, but what I really want is for the video to return to it's initial state. This means it would show the poster image if specified and would start from the beginning if the user hit play again.

我查看了所有文档,我只能找到方法暂停

I looked at all the documentation and I can only find ways to pause.

推荐答案

我能找到的最简单的方法是重置已结束事件的视频源,以便它返回到了开头。处理它的另一种方法是在你换掉视频的时候有一个带有海报图像的div,但这更简单......

The easiest way I have been able to find is to reset the source of the video on the ended event so that it returns to the beginning. The other way to handle it would be to have a div with the poster image in that you swap out for the video, but this is simpler...

<script>
var vid=document.getElementById('myVideo');
vid.addEventListener("ended", resetVideo, false);

function resetVideo() {
    // resets the video element by resetting the source
    this.src = this.src
}
</script>       

这篇关于如何停止播放&lt; video&gt;元素并将其恢复到原始状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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