Youtube iframe API事件不适用于IOS设备

时间:2016-05-19 09:46:31

标签: javascript ios youtube youtube-iframe-api

嗨我想在我的YouTube视频结束时做活动。事件onStateChange适用于桌面和机器人完美,但在IOS设备上,当你的视频播放结束时不会改变,因为IOS在内置播放器中打开youtube。这是我的javascript:

// create youtube player
    var player;
    function onYouTubePlayerAPIReady() {
      player = new YT.Player('player', {
        height: '340',
        width: '850',
        videoId: 'xnh7zOFes-4',
        playerVars: {
          controls: 0,
          showinfo: 0,
          rel: 0
        },
        events: {
          'onStateChange': onPlayerStateChange
        }
      });
    }

    function onPlayerStateChange(event) {
      if(event.data === 0) {
        $('.mobile').fadeOut();
        $('.newsletter').css('display','flex');
      }
    }

1 个答案:

答案 0 :(得分:0)

我认为应该调用你的函数:onYouTubeIframeAPIReady():

function onYouTubeIframeAPIReady() {
  player = new YT.Player('player', {
    height: '340',
    width: '850',
    videoId: 'xnh7zOFes-4',
    playerVars: {
      controls: 0,
      showinfo: 0,
      rel: 0
    },
    events: {
      'onStateChange': onPlayerStateChange
    }
  });
}