我建立了一个包含嵌入式 youtube 视频的网站。直到最近他们还在所有设备上工作,但最近他们已经停止在 iPhone(和 iTouch)上工作。
视频仅播放几秒钟,然后仅显示黑屏。控制台显示常见的 youtube 错误,桌面上的 chrome 和 iphone 上的 safaris 相同:
无法将消息发布到....收件人有来源....
阻止具有来源 .... 的帧访问具有来源 .... 的帧。协议、域和端口必须匹配。
加载视频播放器的 js 改编自 youtube API 示例
// the width of player
var plwidth = 274;
var plheight = 171;
// This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
// This is a protocol-relative URL as described here:
tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// Create an <iframe> (and YouTube player) when the buttons are pressed.
function onYouTubeIframeAPIReady(){
//alert('youtube downloaded');
var player;
var buttons = document.getElementsByClassName('playbutton');
for(var i = 0; i < buttons.length; i++){
buttons[i].style.display = "block";
}
// display play buttons
var button = document.getElementById('playbutton');
button.onclick = function(){
player = new YT.Player('player', {
height: plheight,
width: plwidth,
videoId: 'wr7-K42RXh8',
events: {
'onReady': onPlayerReady,
}
});
return false;
}
}
// The API will call this function when the video player is ready.
function onPlayerReady(event) {
var videoplaceholder = document.getElementById('videoplaceholder');
videoplaceholder.style.display = "none";
event.target.playVideo();
var button = document.getElementById('playbutton');
button.style.display = "none";
}
任何想法为什么它突然停止在 iPhone 上工作(它在 iPad 上工作)?非常感谢任何帮助。
干杯