有没有一种方法可以通过YouTube嵌入的JS api来为用户订阅/关于卡的视频节目画上句号。我到处找,似乎找不到任何方法。除了JS api之外,还有其他解决方案吗?也许用DOM或其他方法添加或复制?谢谢
示例:https://www.dropbox.com/s/ivtcxnbszrylwzi/Screenshot%202014-04-09%2015.53.21.png
如果要使用iFrame API,一种可能性是绑定到playerStateChange事件并侦听YT.PlayerState.ENDED事件。。。当你听到它时,你会用订阅按钮替换视频。类似这样的设置:
<html>
<body>
<div id="myPlayer"></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(document.getElementById("myPlayer"), {
width: "853",
height: "480",
videoId: "f3_JLyVgbEA",
events: {
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
// here's where you replace the video with your subscribe button
}
}
</script>
</body>
</html>