以自定义速度(例如3)嵌入YouTube视频 [英] Embedded YouTube video with custom speed (e.g. 3)

查看:97
本文介绍了以自定义速度(例如3)嵌入YouTube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一页中嵌入了YouTube视频,并有一个滑块,可以用来设置播放器速度.

I have an embedded YouTube video in one page and have a slider with which I can set the player speed.

我正在使用player.setPlaybackRate(value);

问题是我希望范围是0.5到3,但是播放器API仅将值限制为预定义的[0.25, 0.5, 1, 1.25, 1.5, 2].

The problem is that I want ranges from 0.5 to 3, but the player API restricts the values only to predefined [0.25, 0.5, 1, 1.25, 1.5, 2].

在YouTube中,我可以使用document.getElementsByTagName("video")[0].playbackRate = 3轻松调整速度,但是在iframe上,我没有这种访问权限.

In YouTube I can easily adjust the speed with document.getElementsByTagName("video")[0].playbackRate = 3 but on the iframe I do not have such access.

推荐答案

您在哪里看到播放器API限制了这些值?在javascript API中,您可以使用 setPlaybackRate 设置建议的播放速率,但它表示没有保证您发送的内容将被设置.您应该使用 getAvailablePlaybackRates 来获取播放速率列表,然后选择合适的播放速率.您可以通过收听 onPlaybackRateChangeevent 来确定实际设置的速率.如果您尝试将其设置为3而不是可用的费率之一,它将四舍五入为最接近的费率1.

Where do you see that the player API restricts the values? In the javascript API, you can use setPlaybackRate to set the suggested playback rate, but it says there is no guarentee that what you send will be set. You should use getAvailablePlaybackRates to get the list of playback rates and then choose an appropriate one. You can figure out what rate it was actually set to by listening to the onPlaybackRateChangeevent. If you try to set it to 3 and that is not one of the available rates, it will round towards 1 to the closest rate.

这篇关于以自定义速度(例如3)嵌入YouTube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆