【发布时间】:2019-01-06 14:34:46
【问题描述】:
我正在将带有 JS 的 YT 视频加载到 div 中 JS:
function onYouTubeIframeAPIReady() {
player = new YT.Player('video1', {
width: 600,
height: 400,
videoId: 'pDMwa1NYceY',
playerVars: {
color: 'white',
controls: 0,
showinfo: 0
},
events: {
onReady: initialize
}
});
}
HTML:
<div id="video1"></div>
这可行,但现在我想将另一个视频加载到同一页面上的第二个 DIV 中
HTML:
<div id="video1"></div>
<div id="video2"></div>
JS:
function onYouTubeIframeAPIReady() {
player = new YT.Player('video1', {
width: 600,
height: 400,
videoId: 'XFmRL-Vuwtc',
playerVars: {
color: 'white',
controls: 0,
showinfo: 0
},
player = new YT.Player('video2', {
width: 600,
height: 400,
videoId: 'fQsHVCDn-bs',
playerVars: {
color: 'white',
controls: 0,
showinfo: 0
},
events: {
onReady: initialize
}
});
}
我该如何进行这项工作?
我为什么要这样做?我想用JS同时控制两个YouTube视频。
【问题讨论】:
-
您必须修改:1)
player变量应该与您的video2不同。 2)不清楚是否要同时播放和暂停所有带有JS的YouTube视频,对于后者,我已经添加了答案。