自动播放的Javascript工程对浏览器,但不能在iPad上

问题描述 投票:1回答:1

我复制的一则讯息代码,并修改了一些。自动播放我的电脑正常工作(使用javascript),但不能在iPad上。我一直在试图与自动播放:1内onYouTubeIframeAPIRead,但它并不能帮助。

<!-- 1. The <iframe> (and video player) will replace this <div> tag.-->
<div id="player">
</div>

  // 2. This code loads the IFrame Player API code asynchronously.
  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() {
    player = new YT.Player('player', {
      height: '100%',
      width: '100%',
      videoId: '<?php echo $video;?>',
      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, <?php echo $length*1000+2000;?>);
      done = true;
    }
  }
  function stopVideo() {
    player.stopVideo();
  }
</script>
javascript ipad autoplay
1个回答
0
投票

iOS的自动播放模块在具有音频轨道,并通过一个处理程序,它不是在同一个直接背景下的用户交互autoplayed视频。

相关博客文章:https://webkit.org/blog/6784/new-video-policies-for-ios/

你会想这个绑定到一个处理程序,并保持相同的整体背景下,使自动播放是允许的。我相信,Chrome的也将很快实施这一政策。

© www.soinside.com 2019 - 2024. All rights reserved.