gpt4 book ai didi

javascript - YouTube onStateChange 事件突然不起作用

转载 作者:行者123 更新时间:2023-12-03 06:01:16 25 4
gpt4 key购买 nike

直到大约两周前,我一切都运转良好。我没有更改任何代码。

function loadYtVideo(video, advert, advert_link, splash, splash_link){
var params = { allowScriptAccess: "always", wmode: "transparent" };
var atts = { id: "eda-player", wmode: "transparent" };
var swfobject;
adv.orig = video;
swfobject.embedSWF("https://www.youtube.com/v/"+adv.orig+"?rel=0&enablejsapi=1&playerapiid=ytplayer","ytapiplayer", "719", "404", "8", null, null, params, atts);
}

function onYouTubePlayerReady(playerId) {
//It's fired
edaplayer = document.getElementById('eda-player');
edaplayer.addEventListener("onStateChange", "playerState");
}

function playerState(state) {
//it's not fired
console.log(state);
}

<div class="adv-video">
<div id="ytapiplayer">
<script>
$(document).ready(function(){
loadYtVideo($.getUrlVar('ytVideo'), 'eM2ja9LE0YE', 'http://wilmax.ru/', '', '');
});
</script>
</div>
</div>

我发现帖子有类似的问题,但这些帖子中的解决方案在这种情况下不起作用。任何帮助将不胜感激。

最佳答案

我建议您转到YouTube IFrame Player API :

The IFrame player API lets you embed a YouTube video player on your website and control the player using JavaScript. Unlike the Flash and JavaScript player APIs, which both involve embedding a Flash object on your web page, the IFrame API posts content to an <iframe> tag on your page. This approach provides more flexibility than the previously available APIs since it allows YouTube to serve an HTML5 player rather than a Flash player for mobile devices that do not support Flash.

Flash APIJS API已被弃用。我不确定它是否仍然适用于当前的 API,这就是为什么我建议您使用 Iframe API

以下是一些可能对您有帮助的来源:

希望这有帮助!

关于javascript - YouTube onStateChange 事件突然不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39742832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com