如何在嵌入的YouTube播放列表上跳过私人视频

时间:2019-11-08 21:55:20

标签: javascript youtube youtube-api

我们正在使用以下代码将最新的YouTube视频嵌入到我们的一个播放列表中。我们已经将视频排队等待明天上线,现在我们的网站显示“视频不可用-视频私有”错误。我们检查了API,但看不到任何会跳过私人视频的playerVar。

有什么主意如何获取基本的YouTube播放列表以跳过私人或不可嵌入的视频?

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

        <script async src="https://www.youtube.com/iframe_api"></script>
        <script>
         function onYouTubeIframeAPIReady() {
          var player;
          player = new YT.Player('muteYouTubeVideoPlayer', {
            width: 940,               // Player width (in px)
            height: 530,              // Player height (in px)
            playerVars: {
              listType:'playlist',
              list: '{{LIST_ID}}',
              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();
              }
            }
          });
         }
        </script>

如果出现错误,我还尝试添加一点来播放下一个视频。它会更改为播放列表中的下一项,但不会播放。

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

        <script async src="https://www.youtube.com/iframe_api"></script>
        <script>
         function onYouTubeIframeAPIReady() {
          var player;
          player = new YT.Player('muteYouTubeVideoPlayer', {
            width: 940,               // Player width (in px)
            height: 530,              // Player height (in px)
            playerVars: {
              listType:'playlist',
              list: '{{LIST_ID}}',
              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();
              },
              onError: function(e){
                e.target.nextVideo();
                e.target.playVideo();
              }
            }
          });
         }
        </script>

0 个答案:

没有答案