嗨,我想在我的YouTube视频结束时进行 Activity 。事件onStateChange可在台式机和android完美版上正常运行,但在youtube视频结束时,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');
      }
    }

最佳答案

我认为应该调用您的函数: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
    }
  });
}

08-17 20:43