我需要为youtube视频实现视频播放速度控制器(例如:以1/2速度播放视频),并且我认为HTML5是目前唯一的方法(如果可能的话).我对HTML5视频了解甚少,但对youtube js API了解很多.谁能指出我正确的方向?如果该解决方案仅在某些浏览器中有效,则可以.
解决方法:
新的iframe API可让您控制视频的速度:
iframe api reference: Setting the playback rate
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 :)
},
}
});
}
原文地址:https://codeday.me/bug/20191013/1907558.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。