The Google example demonstrates the problem best:
https://developers.google.com/youtube/youtube_player_demo
Change the "Rate" and you will see the video rate/speed does not change.
The Google example demonstrates the problem best:
https://developers.google.com/youtube/youtube_player_demo
Change the "Rate" and you will see the video rate/speed does not change.
Not sure why the setPlaybackRate
doesn't work in the YouTube Player Demo website, but it surely works if your try it.
This is the code I used and you can check the working 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>
Looks like you just have to explicitly set the rate format:
let rate = 2;
player.setPlaybackRate(parseInt(rate));