HTML5 视频 javascript 控件 - 重新启动视频

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8402158/
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-08-24 05:52:10  来源:igfitidea点击:

HTML5 video javascript controls - restart video

javascripthtmlvideo

提问by rom

I know how to start and stop a video with play() and pause(), but how do I put a video back to the start in HTML5 using javascript? is there a way to move the pointer back to the start?

我知道如何使用 play() 和 pause() 开始和停止视频,但是如何使用 javascript 将视频放回到 HTML5 中的开头?有没有办法将指针移回起点?

回答by Quentin

Set the currentTimeproperty back to 0.

将该currentTime属性设置回0.

回答by Matyas

To have a proper stopfunctionality you could do the following:

要获得适当的stop功能,您可以执行以下操作:

var video = document.getElementById('vidId');
// or video = $('.video-selector')[0];
video.pause();
video.currentTime = 0;
video.load();

Note: This is the only version that worked for me in chrome using nodejs(meteorjs) in the backend, serving webm, mp4, oggfiles

注意:这是在 chrome 中唯一对我有用的版本,在后端使用nodejs( meteorjs) ,服务webm, mp4,ogg文件

回答by macmakkara

load() will reload video and put it back to start

load() 将重新加载视频并将其放回开始