以下适用于除Safari 11之外的所有现代桌面浏览器,其中'onStateChange'似乎不断激发,我认为这是导致以下错误的原因:
'无法加载资源:服务器响应状态为413(HTTP / 2.0 413)'
陌生人仍然。如果我点击页面上的任何地方,视频将真正开始播放。
编辑: 仅供参考我在api中尝试了autoplay = 1,然后在事实之后将& autoplay = 1添加到iframe的src。
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
var player;
player = new YT.Player('player', {
videoId: 'ID-HERE',
playerVars: { 'autoplay': 0, 'controls': 0 },
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
$('#player').delay(1200).fadeIn()
}
// 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.
function onPlayerStateChange(event) {
// if (event.data == YT.PlayerState.PLAYING && !done) {
console.log('state change, play');
event.target.playVideo();
}
function stopVideo() {
console.log('video stop');
}
答案 0 :(得分:0)
尝试改变:
event.target.playVideo(); 至 player.playVideo();
这里的工作正常。我在这个版本的Safari中遇到了同样的问题。 当我改变这种方式时,它可以与其他浏览器一起使用。