YouTube Java 脚本player.setPlaybackRate() API 不再工作

2024-03-19

谷歌的例子最好地说明了这个问题:

https://developers.google.com/youtube/youtube_player_demo https://developers.google.com/youtube/youtube_player_demo

更改“速率”,您将看到视频速率/速度没有改变。


不知道为什么setPlaybackRate不起作用YouTube 播放器演示网站 https://developers.google.com/youtube/youtube_player_demo,但如果你尝试一下,它肯定会起作用。

这是我使用的代码,您可以检查工作中的jsfiddle https://jsfiddle.net/MauricioSOes/m96g7wsc/:

// 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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

YouTube Java 脚本player.setPlaybackRate() API 不再工作 的相关文章

随机推荐