【发布时间】:2015-05-31 15:34:42
【问题描述】:
我在使用 YouTube 播放器工具 - Iframe API 播放视频时遇到一些错误。我在浏览器的控制台窗口中遇到这 6 个错误
1.在“DOMWindow”上执行“postMessage”失败:提供的目标原点(“https://www.youtube.com”)与接收窗口的原点(“http://127.0.0.1”)不匹配。
2.GET chrome-extension://boadgeojelhgndaghljhdcfkmllpafd/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>
我需要做些什么来消除这些错误?
【问题讨论】:
标签: php youtube-api youtube-javascript-api