使用YouTube播放器工具 - Iframe API播放视频时出现的错误很少。我在浏览器的控制台窗口中收到了这6个错误
1.无法执行' postMessage'在' DOMWindow':提供的目标来源(' https://www.youtube.com')与收件人窗口的来源不匹配(' http://127.0.0.1 ')
。 2.GET chrome-extension://boadgeojelhgndaghljhdicfkmllpafd/cast_sender.js net :: ERR_FAILED
3.GET chrome-extension://dliochdbjfkdbacpmhlcpmleaejidimm/cast_sender.js net :: ERR_FAILED
4.GET chrome-extension://hfaagokkkhdbgiakmmlclaapfelnkoah/cast_sender.js net :: ERR_FAILED
5.GET chrome-extension://fmfcbgogabcbclcofgocippekhfcmgfj/cast_sender.js net :: ERR_FAILED
6.GET chrome-extension://enhhojjnijigcajfphajepfemndkmdlo/cast_sender.js net :: ERR_FAILED
我的index.php是
<html>
<head>
</head>
<body>
<div id='player'></div>
<!--iframe id="player" type="text/html" width="640" height="390"
src="https://www.youtube.com/embed/M7lc1UVf-VE?enablejsapi=1&origin=http://example.com"
frameborder="0"></iframe-->
<script>
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 2. This code loads the IFrame Player API code asynchronously.
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '500',
width: '500',
videoId: 'wbLBHYAd0kE',//videos[currentid],
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 10000);
done = true;
}
}
function stopVideo() {
alert();
player.stopVideo();
}
</script>
</body>
</html>
我需要做些什么来消除这些错误?
答案 0 :(得分:0)
第一个错误:
转
tag.src = "http://www.youtube.com/iframe_api";
到
tag.src = "https://www.youtube.com/iframe_api";
错误2-6:这是官方Chromecast JavaScript库的已知错误。它不是以静默方式失败,而是将这些错误消息转储到所有非Chrome浏览器以及Chromecast扩展程序不存在的Chrome浏览器中。