问题描述
这是我的第一篇文章,希望我遵守所有规则.
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.
在代码中,URL 是: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,只播放播放列表的第一个视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!