YouTube API 播放列表随机播放不起作用? [英] YouTube API playlist shuffle not working?
问题描述
我一直在尝试设置我的 youtube api 来随机播放我的播放列表,但顺序一直都一样......
I have been trying to set-up my youtube api to shuffle my playlist but the order is the same all the time...
这是我从中获取代码的链接https://developers.google.com/youtube/iframe_api_reference#setShuffle
Here is the link where I am getting my code from https://developers.google.com/youtube/iframe_api_reference#setShuffle
我说得对吗?
下面是我的代码
<div id="player"></div>
<script>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
events: {
'onReady': onPlayerReady
}
});
}
function onPlayerReady(event) {
player.loadPlaylist({'listType': 'playlist', 'list': 'PLF776D41D8211F340','index': '0','startSeconds': '0','suggestedQuality': 'hd720'});
player.setShuffle({'shufflePlaylist' : 1});
}
</script>
我尝试将 shufflePlaylist 设置为true",我尝试过使用提示播放列表而不是加载播放列表,我什至尝试将 shufflePlaylist 放在加载播放列表中......没有任何内容被随机播放.
I have tried setting shufflePlaylist to 'true', I have tried cueplaylist instead of loadplaylist and I have even tried putting the shufflePlaylist in the load Playlist...nothing is getting shuffled.
我已经调查过这个问题,我发现这是 API 的问题,但那是 2 年前的问题,是否有解决此问题的方法?
I have looked into this and I see that it was an issue with the API, but that was 2 years ago, is there a solution to this issue?
以下是我尝试过但没有奏效的方法
Below is what I have tried and didn't work
player.setShuffle(1);
player.setShuffle('1');
player.setShuffle(true);
player.setShuffle('true');
player.setShuffle({'shufflePlaylist' : true});
player.setShuffle({'shufflePlaylist' : 1});
player.setShuffle({'shufflePlaylist' : 'true'});
player.setShuffle({'shufflePlaylist' : '1'});
我也尝试从这里复制和示例....https://developers.google.com/youtube/youtube_player_demo
I have also tried copying and example from here....https://developers.google.com/youtube/youtube_player_demo
在您加载播放列表并单击按钮后,Shuffle 将在此处工作.
The Shuffle works here after u load the playlist and click a button.
推荐答案
这是一个尚未修复的已知错误 - 请参阅此 post
This is a known bug that is yet to be fixed - see this post
一种解决方法是将一个随机数传递给 playVideoAt
,如下所示:
A work around however is to pass a random number to playVideoAt
, as follows:
var getRandom = function(min, max) {
return Math.random() * (max - min) + min;
};
var playRandomTrack = function() {
num = getRandom(0, 99);
player.playVideoAt(num);
};
这篇关于YouTube API 播放列表随机播放不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!