我正在按照指南here将Twitch视频播放器嵌入到网页中。
我正在将完全相同的代码复制到HTML文件中并运行它,但它说“embed.getPlayer()不是函数”。最重要的是,视频播放器即使不应该自动播放也会自动播放。
var embed = new Twitch.Embed("twitch-embed", {
width: 854,
height: 480,
channel: "monstercat",
layout: "video",
autoplay: false
});
var player = embed.getPlayer();
player.addEventListener(Twitch.Player.PLAY, function() {
changeAdvertisementBanner();
});
player.play();
答案 0 :(得分:0)
对于交互式播放器,请检查以下文档: https://dev.twitch.tv/docs/embed/video-and-clips/#interactive-frames-for-live-streams-and-vods
如果您使用这种方式创建视频播放器,那么我们可以听所有这样的更改:
<script type="text/javascript">
var options = {
width: "255",
height: "350",
channel: "AnyChannelName!",
};
var player = new Twitch.Player("UniqueID", options);
player.addEventListener(Twitch.Player.READY, function () {
alert("Player Is Ready");
});
player.addEventListener(Twitch.Player.PAUSE, function () {
alert("PAUSE");
});
player.addEventListener(Twitch.Player.PLAY, function () {
alert("PLAY");
});
</script>