我需要为两个视频加载一个seekto链接。
我可以用这个代码做一个视频:
<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: '321',
width: '530',
videoId: 'IZ4uxjWUmtY',
playerVars: {
autoplay: 0,
rel: 0,
},
events: {
//'onReady': onPlayerReady
//'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
event.target.playVideo();
}
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function seekTo(secondes) {
player.seekTo(secondes);
}
</script>
<a class="conseil" href="javascript:void(0);" onClick="seekTo('0');">Link1</a>
<a class="conseil" href="javascript:void(0);" onClick="seekTo('605');">Link2</a>
我不知道如何加载2个视频与抖音链接。其他人知道怎么做吗?
为每个视频创建不同的player
:
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player1 = new YT.Player('player', {
height: '321',
width: '530',
videoId: 'IZ4uxjWUmtY',
playerVars: {
autoplay: 0,
rel: 0,
},
events: {
//'onReady': onPlayerReady
//'onStateChange': onPlayerStateChange
}
});
player2 = new YT.Player('player', {
height: '321',
width: '530',
videoId: 'IZ4uxjWUmtY',
playerVars: {
autoplay: 0,
rel: 0,
},
events: {
//'onReady': onPlayerReady
//'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
event.target.playVideo();
}
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function seekToPlayer1(secondes) {
player.seekTo(secondes);
}
function seekToPlayer2(secondes) {
player.seekTo(secondes);
}
链接1Link2