Javascript 如何更改 HTML5 中视频的播放速度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3027707/
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
How to change the playing speed of videos in HTML5?
提问by Young
How to change the video play speed in HTML5? I've checked video tag's attributesin w3school but couldn't approach that.Any help would be appreciated!
如何更改 HTML5 中的视频播放速度?我已经在 w3school 中检查了视频标签的属性,但无法接近。任何帮助将不胜感激!
回答by Jeremy Visser
According to this site, this is supported in the playbackRateand defaultPlaybackRateattributes, accessible via the DOM. Example:
根据这个站点,这在playbackRate和defaultPlaybackRate属性中得到支持,可通过 DOM 访问。例子:
/* play video twice as fast */
document.querySelector('video').defaultPlaybackRate = 2.0;
document.querySelector('video').play();
/* now play three times as fast just for the heck of it */
document.querySelector('video').playbackRate = 3.0;
The above workson Chrome 43+, Firefox 20+, IE 9+, Edge 12+.
以上适用于 Chrome 43+、Firefox 20+、IE 9+、Edge 12+。
回答by Andrey Panasyuk
Just type
只需输入
document.querySelector('video').playbackRate = 1.25;
in JS console of your modern browser.
在现代浏览器的 JS 控制台中。
回答by Abdul Quadir
You can use this code:
您可以使用此代码:
var vid = document.getElementById("video1");
function slowPlaySpeed() {
vid.playbackRate = 0.5;
}
function normalPlaySpeed() {
vid.playbackRate = 1;
}
function fastPlaySpeed() {
vid.playbackRate = 2;
}
回答by Mattyduke1
javascript:document.getElementsByClassName("video-stream html5-main-video")[0].playbackRate = 0.1;
you can put any number here just don't go to far so you don't overun your computer.
您可以在此处输入任何数字,但不要走得太远,以免过度运行计算机。

