问题描述
我想用 https://jsfiddle.net/g1xfh7rd/ 切换播放列表,但它总是重新加载相同的初始播放列表.我尝试了所有建议的解决方案 YouTube 播放器 API 列表和视频,但没有工作
<div onClick="loadPlaylist()">加载另一个</div><script async src="https://www.youtube.com/iframe_api"></script><脚本>//1. ytplayer 代码:https://developers.google.com/youtube/player_parameters#IFrame_Player_APIvar tag = document.createElement('script');tag.src = "https://www.youtube.com/player_api";var firstScriptTag = document.getElementsByTagName('script')[0];firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);var 播放器;函数 onYouTubePlayerAPIReady(){player = new YT.Player('ytplayer',{高度:'390',宽度:'640',玩家变量:{listType:'播放列表',列表:'RDEMe12_MlgO8mGFdeeftZ2nOQ'}});}函数加载播放列表(){player.loadPlaylist('PLuvQYuQ7n4rAtqY1dDvhts08zBoisI8xA');}
它工作正常,如果您使用 对象语法的loadPlaylist()并添加一个player.stopVideo().
函数 loadPlaylist() {player.stopVideo();player.loadPlaylist({ list: 'PLuvQYuQ7n4rAtqY1dDvhts08zBoisI8xA' });}
I want to switch playlist with https://jsfiddle.net/g1xfh7rd/ but it does always reload the same initial playlist. I tried all solutions suggested YouTube Player API list with videos and it didn't work
<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>
It works fine, if you use the object syntax of loadPlaylist() and add a player.stopVideo().
function loadPlaylist() {
player.stopVideo();
player.loadPlaylist({ list: 'PLuvQYuQ7n4rAtqY1dDvhts08zBoisI8xA' });
}
这篇关于用于列表的 youtube 播放器 API 始终播放初始视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!