我会显示指向youtube视频的链接列表。
document.getElementById('videos').innerHTML += "<div>"
+ "<a href='#' onclick='showVideo(\"" + videoid + "\"); return false'>" + videotitle + "</a>" + videodescription + ""
+ "</div>";
点击任意链接,视频将在其div中播放。
function showVideo(arg) {
console.log(arg);
var player;
player = new YT.Player('response', {
videoId: arg,
// height: '700',
// width: '1000',
playerVars: {
controls: 1, // 1 is default value
autoplay: 1,
disablekb: 0, // 0 is the default value
enablejsapi: 1,
iv_load_policy: 3,
modestbranding: 1,
showinfo: 0,
rel: 0,
fs: 0 //Setting this parameter to 0 prevents the fullscreen button from displaying in the player.
//The default value is 1, which causes the fullscreen button to display.
}
})
// player.destroy()
}
我点击显示列表中的其他链接,我希望将现有视频替换为新视频,但这不会发生,仍会显示第一个视频。 是不是变量播放器再次实例化? 我需要做些什么来实现这个目标?