问题描述
我需要为 youtube 视频实现一个视频播放速度控制器(例如:以 1/2 速度播放视频),我认为 HTML5 目前是唯一的方法(如果可能的话).我对 HTML5 视频知之甚少,但我对 youtube js API 了解很多.谁能指出我正确的方向?如果该解决方案仅适用于某些浏览器,那也没关系.
I need to implement a video playback speed controller (e.g.: play the video at 1/2 speed) for youtube videos, and I'm thinking that HTML5 is currently the only way to do this (if it's even possible). I know very little about HTML5 video, but I know a lot about the youtube js API. Can anyone point me in the right direction? It's okay if the solution will only work in some browsers.
推荐答案
新的 iframe api 允许您控制视频的速度:
The new iframe api allows you to control the speed of the video:
iframe api 参考:设置播放速率
默认播放速率为 1,表示视频正在以正常速度播放.播放速率可能包括 0.25、0.5、1、1.5 和 2 等值.
The default playback rate is 1, which indicates that the video is playing at normal speed. Playback rates may include values like 0.25, 0.5, 1, 1.5, and 2.
还有:
调用此函数并不能保证播放速率会真正改变.
Calling this function does not guarantee that the playback rate will actually change.
示例代码:
function onYouTubeIframeAPIReady() {
var player;
player = new YT.Player('player', {
videoId: 'M7lc1UVf-VE',
playerVars: { 'autoplay': 1, 'controls': 0 },
events: {
'onReady': function(e){
// e.target = player
e.target.setPlaybackRate(0.5); // set to half speed
e.target.playVideo(); // watch lolcats in slow motion :)
},
}
});
}
这篇关于YouTube 视频的播放速度控制?HTML5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!