Html HTML5 将 youtube 速度从 url 提高 2 倍?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22604934/
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
HTML5 increase youtube speed 2x from url?
提问by tonni
I would like to know how to speed up a youtube video 2x without the user clicking on the HTML5 (of the video), but instead by modifying the URL.
我想知道如何在不点击(视频的)HTML5 的情况下将 youtube 视频加速 2 倍,而是通过修改 URL。
For example, I know how to watch video starting at a specific time by appending to the URL the parameter &t=1m1s
(for 1 minute and one second). Is it possible to use a similar method to speed up the video 2x?
例如,我知道如何通过向 URL 附加参数&t=1m1s
(1 分 1 秒)来观看从特定时间开始的视频。是否可以使用类似的方法将视频加速 2 倍?
What parameters should I add to the URL to watch video in double speed (I'm using html5)?
我应该在 URL 中添加哪些参数以双倍速度观看视频(我使用的是 html5)?
回答by jpreynat
There's no way to change playback speed by URL arguments.
无法通过 URL 参数更改播放速度。
Anyway, if you're working with HTML, you can take advantage of the YouTube Player iFrame API.
无论如何,如果您使用 HTML,您可以利用 YouTube Player iFrame API。
Here's how to configure your player with all the JavaScript: https://developers.google.com/youtube/iframe_api_reference#Getting_Started
以下是使用所有 JavaScript 配置播放器的方法:https: //developers.google.com/youtube/iframe_api_reference#Getting_Started
And here's the function you're looking for to set playback speed: https://developers.google.com/youtube/iframe_api_reference#Playback_rate
这是您正在寻找的用于设置播放速度的功能:https: //developers.google.com/youtube/iframe_api_reference#Playback_rate
So you can edit your onPlayerReady function like this:
所以你可以像这样编辑你的 onPlayerReady 函数:
function onPlayerReady(event) {
player.setPlaybackRate(2); // This is what you're looking for
event.target.playVideo();
}
You can of course pass on step 5 of the documentation as this will stop your video from playing after six seconds.
您当然可以传递文档的第 5 步,因为这将在 6 秒后停止播放您的视频。
If you have trouble setting that up, I'll edit a JSFiddle later (couldn't do it at work as my Flash plugin won't launch).
如果您在设置时遇到问题,稍后我将编辑一个 JSFiddle(无法在工作中进行,因为我的 Flash 插件无法启动)。
Update :
更新 :
Here's the JSFiddle working fine with this code exactly: http://jsfiddle.net/jpreynat/e11oy0eu/
这是 JSFiddle 与此代码完全一致的工作:http: //jsfiddle.net/jpreynat/e11oy0eu/
回答by Alicia
I was trying to do this exact same thing earlier this week.
本周早些时候我试图做同样的事情。
A solution purely from a URL parameter isn't possible. (or if it is, it's not documentation here: https://developers.google.com/youtube/player_parameters)
纯粹从 URL 参数中获得解决方案是不可能的。(或者如果是,它不是这里的文档:https: //developers.google.com/youtube/player_parameters)
I came accros this JSFiddle by Johan Preynat: http://jsfiddle.net/jpreynat/e11oy0eu/
我来到了 Johan Preynat 的这个 JSFiddle:http: //jsfiddle.net/jpreynat/e11oy0eu/
Worked for me, so hopefully it'll be useful for you too
为我工作,所以希望它对你也有用
HTML
HTML
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
JavaScript
JavaScript
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
player.setPlaybackRate(2);
event.target.playVideo();
}
See also the YouTube documentation on this: https://developers.google.com/youtube/iframe_api_reference
另请参阅 YouTube 文档:https: //developers.google.com/youtube/iframe_api_reference
回答by ImposterMo is t strikethru
Can you inject a shift > or < from users input via url or easier javascript? Maybe its easier to force the hot key press from the users end.
您可以通过 url 或更简单的 javascript 从用户输入中注入 shift > 或 <?也许从用户端强制按下热键更容易。