有没有办法通过JS api for YouTube嵌入式向用户订阅/关于卡片结束视频节目。我搜索了高低,似乎无法找到任何方法。 JS api之外的任何其他解决方案?也许用DOM或其他方法添加或复制?谢谢!
示例: https://www.dropbox.com/s/ivtcxnbszrylwzi/Screenshot%202014-04-09%2015.53.21.png
答案 0 :(得分:0)
如果您使用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>