嵌入 Youtube 播放列表,但从随机视频开始 [英] Embedding Youtube playlist but starting from random video

查看:17
本文介绍了嵌入 Youtube 播放列表,但从随机视频开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了很多搜索,但到目前为止找不到解决方案......

I've done plenty of searching but can't find a olsution so far...

我有一个 Youtube 播放列表.我想把它嵌入到一个网站上.但不是总是从第一个视频开始,我希望它从一个随机视频开始,或者至少是一个特定视频(我可以使用服务器端代码随机选择).

I have a Youtube playlist. I want to embed it on a website. But instead of always starting at the first video, I want it to start at either a random video, or a at least a specific video (which I can randomly select with server side code).

我查看了 iframe 嵌入 URL 的选项,但看不到允许我对此进行任何控制的参数.有可能吗?

I have looked at the options for the iframe embed URL and can't see a parameter that allows me any control over this. Is it possible to do?

否则我认为我需要在 JavaScript 中使用 API 做一些事情.有人可以粘贴或指向我可以用来完成此操作的一些示例代码吗,因为我之前没有使用过 Youtube API?

Otherwise I presume I would need to do something in JavaScript with the API. Can someone paste or point me to some example code that I could use to accomplish this as I haven't used the Youtube API before?

推荐答案

在你的服务器上生成一个随机数,然后在 url 中使用 index 参数.这是一个示例,播放列表将通过添加 index=7 从第 7 项开始.

Generate a random number on your server and then use the index parameter in the url. Here's an example where the playlist will start on the 7th item by adding index=7.

<iframe width="560" height="315" src="http://www.youtube.com/embed/videoseries?list=PL9C5815B418D1508E&index=7" frameborder="0" allowfullscreen></iframe>

另一种选择是使用 js api,调用 loadPlaylist 并包含 index 参数.https://developers.google.com/youtube/js_api_reference#loadPlaylist

The other option is to use the js api, and call loadPlaylist and include the index argument. https://developers.google.com/youtube/js_api_reference#loadPlaylist

**由于 Google 引入了 YouTube 3.0 API,index 参数现在从零开始.因此,如果我们想从第 7 个视频开始,我们将修改上面的示例,使用 &index=6 而不是 &index=7.

** Since Google introduced YouTube's 3.0 API, the index parameter is now zero-based. Therefore, if we wanted to start at the 7th video, we'd modify the example above using &index=6 instead of &index=7.

(链接:https://developers.google.com/youtube/iframe_api_reference#Queueing_Functions_for_Playlists)

这篇关于嵌入 Youtube 播放列表,但从随机视频开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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