为什么 YouTube JavaScript Player API 打开的 URL 与我代码中的 URL 不同,并且只播放播放列表的第一个视频? [英] Why YouTube JavaScript Player API open a different URL than the one in my code, and just play the first video of a playlist?

查看:18
本文介绍了为什么 YouTube JavaScript Player API 打开的 URL 与我代码中的 URL 不同,并且只播放播放列表的第一个视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一篇文章,希望我尊重所有规则.

It is my first post, I hope I respected all the rules.

我正在尝试在我网站的一个页面上发布:随机播放/静音/自动播放 YouTube 播放列表.

I am trying to publish on a page of my website a: shuffle / muted / autoplay youtube playlist.

我使用了 AS3 方法和 SWFObject.

I used the method AS3, with SWFObject.

使用以下代码一切正常,但几周后,播放器没有检测到我的播放列表,只播放第一个视频.

Everything worked fine with the following code, but since few weeks, the player doesn't detect my playlist and just play the first video.

在代码中,网址是:https://www.youtube.com/v/HuIGf4IJzdM&list=PLo-QIlIZx6myBxEysxrWoE-f58-psKGji

In the code, the URL is : https://www.youtube.com/v/HuIGf4IJzdM&list=PLo-QIlIZx6myBxEysxrWoE-f58-psKGji

但是当我打开页面的页面时,它打开了以下链接:https://www.youtube.com/v/HuIGf4IJzdM&list=o-QIlIZx6myBxEysxrWoE-f58-psKGji

But when I open the page of the page, it open the following link : https://www.youtube.com/v/HuIGf4IJzdM&list=o-QIlIZx6myBxEysxrWoE-f58-psKGji

这是代码,如果我没有错的话,它可以正常工作:

Here is the code wich, if I am not wrong, works fine precedently :

<script src="https://www.google.com/jsapi"></script>
<script src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<div id="ytapiplayer">You need Flash player 8+ and JavaScript enabled to view this video.</div>
<script type="text/javascript">
google.load("swfobject", "2.2");
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.playVideo();
ytplayer.setShuffle(true);
ytplayer.mute();
}
var params = {allowScriptAccess: "always" , allowFullScreen : "true"};
var atts = { id: "myytplayer" };

swfobject.embedSWF("https://www.youtube.com/v/HuIGf4IJzdM&list=PLo-QIlIZx6myBxEysxrWoE-f58-psKGji&index=0&feature=plpp_play_all?enablejsapi=1&playerapiid=ytplayer&allowFullScreen=true&version=3&loop=1&autohide=1",
"ytapiplayer", "50%", "50%", "10", null, null, params, atts)
</script>

如果有人能帮我找到这个问题的解决方案,非常感谢!!

Thank you a lot if someone can help me to fin the solution to this problem !!

推荐答案

我终于找到了一种替代方法,让它与 iframe 一起工作.

I finally found an alternative way to make it work with an iframe.

代码如下:

<div id="player"></div>

<script>

  var tag = document.createElement('script');

  tag.src = "https://www.youtube.com/iframe_api";
  var firstScriptTag = document.getElementsByTagName('script')[0];
  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

  var player;
  function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
      height: '100%',
      width: '100%',
      events: {
        'onReady': onPlayerReady
      }

    });
  }

  function onPlayerReady(event) {

    event.target.loadPlaylist({'listType': 'playlist',
                               'list': 'PLo-QIlIZx6myBxEysxrWoE-f58-psKGji',
                               'index': '0'
                              });
      event.target.mute();
      event.target.setLoop(true);
    setTimeout( function() { 
        event.target.setShuffle(true); 
    }, 2000);
      }
</script>

谢谢你的帮助:-)

这篇关于为什么 YouTube JavaScript Player API 打开的 URL 与我代码中的 URL 不同,并且只播放播放列表的第一个视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆