【问题标题】:Embed YouTube Video Autoplay that plays sound on Mobile嵌入在移动设备上播放声音的 YouTube 视频自动播放
【发布时间】:2017-09-30 14:10:51
【问题描述】:

www.aerlawgroup.com

我使用以下代码在网站上嵌入了带有 AUTOPLAY 和 MUTE 的 YT 视频。在移动设备上,它不会自动播放(这很好)。但是,当我在移动设备上点击“播放”时,视频播放时没有声音(因此它仍处于静音状态)。

是否可以插入代码使其播放声音?

<div id="muteYouTubeVideoPlayer"></div>

<script async src="https://www.youtube.com/iframe_api"></script>
<script>
 function onYouTubeIframeAPIReady() {
  var player;
  player = new YT.Player('muteYouTubeVideoPlayer', {
    videoId: 'YOUR_VIDEO_ID', // YouTube Video ID
    width: 560,               // Player width (in px)
    height: 316,              // Player height (in px)
    playerVars: {
      autoplay: 1,        // Auto-play the video on load
      controls: 1,        // Show pause/play buttons in player
      showinfo: 0,        // Hide the video title
      modestbranding: 1,  // Hide the Youtube Logo
      loop: 1,            // Run the video in a loop
      fs: 0,              // Hide the full screen button
      cc_load_policy: 0, // Hide closed captions
      iv_load_policy: 3,  // Hide the Video Annotations
      autohide: 0         // Hide video controls when playing
    },
    events: {
      onReady: function(e) {
        e.target.mute();
      }
    }
  });
 }

 // Written by @labnol 
</script>

【问题讨论】:

    标签: audio video youtube youtube-api youtube-javascript-api


    【解决方案1】:

    只需交换这个:e.target.mute();

    with: e.target.setVolume(0);

    【讨论】:

      猜你喜欢
      • 2022-10-17
      • 1970-01-01
      • 2017-11-03
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 2018-05-25
      • 2021-05-01
      相关资源
      最近更新 更多