javascript YouTube 播放列表 - 随机播放/随机函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9378957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 06:29:08  来源:igfitidea点击:

YouTube Playlists - Shuffle/Random Function

javascriptyoutubeembedplaylist

提问by John the Painter

Is there any way to embed a YouTube playlist that has the ability to shuffle or randomise on the page reload? So, it starts showing one video in the playlist and plays from that point and then when the browser is refreshed, it plays another and so forth.

有什么方法可以嵌入一个 YouTube 播放列表,它可以在页面重新加载时随机播放或随机播放?因此,它开始在播放列表中显示一个视频并从该点开始播放,然后当浏览器刷新时,它会播放另一个等等。

I can do this fairly well with a xml and third party video tool that allows me to play XMLs with a random function, but a lot of the videos in the playlist has copyrighted music so has to be played through the YouTube embed or it won't work.

我可以使用 xml 和第三方视频工具很好地做到这一点,该工具允许我使用随机功能播放 XML,但播放列表中的许多视频都有受版权保护的音乐,因此必须通过嵌入的 YouTube 播放,否则将无法播放工作。

Any ideas? I've tried to do this for months and months.

有任何想法吗?我已经尝试这样做了好几个月了。

I've attached some code below with what sort of works, which I embedded using an iFrame, but it causes IE to constantly refresh and fill up my access logs to the point where it crashes.

我在下面附上了一些代码,其中包含我使用 iFrame 嵌入的工作类型,但它会导致 IE 不断刷新并填充我的访问日志,直到它崩溃为止。

<html>
<head>
</head>
<body onLoad="load()" style="background-color:white">
<script type="text/javascript">
var playlisturl = "http://gdata.youtube.com/feeds/api/playlists/D4607BD824235A91?v=2";
var playlisturls = ["http://gdata.youtube.com/feeds/api/playlists/D4607BD824235A91?v=2"];
var pause_playlist_text = "Pause playlist (loop current video)";
var embed = true;
var swf = false;
var autoplay = false;
var vwidth = 275;
var vheight = 270;
</script>
<script type="text/javascript" src="http://youtube-playlist-randomizer.valami.info/seedrandom.js.pagespeed.ce.FBW5lks-2H.js"></script>
<script type="text/javascript" src="http://youtube-playlist-randomizer.valami.info/playlist-min.js.pagespeed.ce.mjzbqx3nYo.js"></script>
<object style="width: 275px; height: 270px">
  <param name="movie" value="http://www.youtube.com/v/Yo6dgBCsj2Q?version=3">
  <param name="allowFullScreen" value="true">
  <param name="allowScriptAccess" value="always">
  <embed id="myytplayer" src="http://www.youtube.com/v/Yo6dgBCsj2Q?enablejsapi=1&version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="275px" height="270px">
</object>

<p><button class="sexybutton sexysimple sexyblue" id="previousbutton" onClick="previous()"><span class="prev">Previous</span></button>
<button class="sexybutton sexysimple sexyblue" id="nextbutton" onClick="next()"><span class="next after">Next</span></button></p>
<script type="text/javascript">

document.getElementById('pauseplaylist').style.display = "none"

</script>
</body>
</html>

Many thanks in advance, Richard

非常感谢,理查德

回答by dutchguy

There′s an official "randomize" function available if you enable javascript-control on your player. You create an extra button for randomizing.. or create a function to let it randomize depending on date,time.iP-adress...etc. It works..i′m using it, youtube calls it "SHUFFLE" check the Youtube jS-api pages:

如果您在播放器上启用 javascript-control,则可以使用官方的“随机化”功能。您创建一个额外的按钮来随机化……或者创建一个函数让它根据日期、时间、IP 地址……等随机化。它有效..我正在使用它,youtube 称它为“SHUFFLE” 检查 Youtube jS-api 页面:

https://developers.google.com/youtube/js_api_reference

https://developers.google.com/youtube/js_api_reference