列表的 youtube 播放器 api 始终播放初始视频
youtube player api for list does always play initial video
我想用 https://jsfiddle.net/g1xfh7rd/ but it does always reload the same initial playlist. I tried all solutions suggested YouTube Player API list with videos 切换播放列表,但没成功
<div id="ytplayer"></div>
<div onClick="loadPlaylist()">load another</div>
<script async src="https://www.youtube.com/iframe_api"></script>
<script>
// 1. ytplayer code: https://developers.google.com/youtube/player_parameters#IFrame_Player_API
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady()
{
player = new YT.Player('ytplayer',
{
height: '390',
width: '640',
playerVars:
{
listType:'playlist',
list: 'RDEMe12_MlgO8mGFdeeftZ2nOQ'
}
});
}
function loadPlaylist() {
player.loadPlaylist('PLuvQYuQ7n4rAtqY1dDvhts08zBoisI8xA');
}
</script>
如果您使用 loadPlaylist() 的 object syntax 并添加一个 player.stopVideo()。
function loadPlaylist() {
player.stopVideo();
player.loadPlaylist({ list: 'PLuvQYuQ7n4rAtqY1dDvhts08zBoisI8xA' });
}
我想用 https://jsfiddle.net/g1xfh7rd/ but it does always reload the same initial playlist. I tried all solutions suggested YouTube Player API list with videos 切换播放列表,但没成功
<div id="ytplayer"></div>
<div onClick="loadPlaylist()">load another</div>
<script async src="https://www.youtube.com/iframe_api"></script>
<script>
// 1. ytplayer code: https://developers.google.com/youtube/player_parameters#IFrame_Player_API
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady()
{
player = new YT.Player('ytplayer',
{
height: '390',
width: '640',
playerVars:
{
listType:'playlist',
list: 'RDEMe12_MlgO8mGFdeeftZ2nOQ'
}
});
}
function loadPlaylist() {
player.loadPlaylist('PLuvQYuQ7n4rAtqY1dDvhts08zBoisI8xA');
}
</script>
如果您使用 loadPlaylist() 的 object syntax 并添加一个 player.stopVideo()。
function loadPlaylist() {
player.stopVideo();
player.loadPlaylist({ list: 'PLuvQYuQ7n4rAtqY1dDvhts08zBoisI8xA' });
}