youtube-iframe-api - YouTube Java Script player.setPlaybackRate() API 不再工作
问题描述
Google 示例最能说明问题:
https://developers.google.com/youtube/youtube_player_demo
更改“速率”,您将看到视频速率/速度没有改变。
解决方案
不知道为什么在YouTube 播放器演示网站上setPlaybackRate
不起作用,但如果您尝试一下,它肯定会起作用。
这是我使用的代码,您可以检查工作的 jsfiddle:
// 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: '360',
width: '640',
videoId: '00vnln25HBg',
playerVars: {
'autoplay': 1,
'loop': 1,
'mute': 1
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// Here I set the "setPlaybackRate" value to "2".
function onPlayerStateChange(event) {
player.setPlaybackRate(2);
}
function stopVideo() {
player.stopVideo();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<div id="player"></div>
推荐阅读
- ruby-on-rails - 如何在不迭代的情况下为 ActiveRecord_Relation 中的所有记录分配属性?
- php - 带有插件域的 Laravel 多租户应用程序
- python - 在一个 RDD 中加入两个字符串以在 pyspark 中形成新的 RDD
- visual-studio-code - 在多行中显示选项卡
- ios - 如何使用 SwiftUI 使用“PDF”选择器打开“PDF”?
- python - QLabel 在图像上的映射位置
- python - 更新 Matplotlib 中的单条
- mysql - Mysql 数据库无法使用“loclhost”连接,但可以使用“127.0.0.1”Centos 7 (Cloudlinux) 连接
- reactjs - 在带有查询的 api 调用上触发 useEffect
- pandas - 将 '%H:%M:%S.%f' 转换为 pandas 中的时间