如何使用侧边栏嵌入youtube播放列表 [英] How to embed a youtube playlist with a sidebar

查看:210
本文介绍了如何使用侧边栏嵌入youtube播放列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将带有侧边栏的youtube播放列表嵌入到我的html页面中.

I'm trying to embed a youtube playlist with a sidebar to my html page.

播放列表本身可以通过以下html代码嵌入:

The playlist itself can be embedded by this html code:

<iframe width="560" height="315" src="https://www.youtube.com/embed/videoseries?list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="1"/>

这将显示播放列表,但没有侧边栏.因此,我现在想在youtube播放列表显示旁边添加侧边栏.

This displays the playlist, but without a sidebar. So I now want to add a sidebar next to the youtube playlist display.

所以最终视图应该是这样的:

So the final view should be something like this:

侧边栏项目应为下一个视频的缩略图.您应该能够滚动/导航到播放列表中未显示的下一个/上一个视频.而且,当您单击侧边栏项目时,显示的视频应更新为单击的视频,并且侧边栏应更新为下一个可用视频.

The sidebar items should be the thumbnail images of the next videos. You should be able to scroll/navigate to the next/previous videos in the playlist that aren't displayed. And when you click on the sidebar items the displayed video should be updated to the clicked video and the sidebar should updated to the next available videos.

在youtube播放列表上,侧边栏显示如下:

On youtube playlist sidebars are displayed like this:

因此,我们希望仅通过图像缩略图更改侧边栏.因此youtube侧边栏的外观更加干净".

So we would like an alteration of that sidebar with only the image thumbnails. So a 'cleaner' look of the youtube sidebar.

注意:该解决方案只能使用html/css/javascript.

Note: The solution should only use html/css/javascript.

这两个问题都问了同样的问题,但是这些问题早已存在,而且iframe和插件解决方案似乎都不再起作用.

These 2 questions have asked the same, but these are from to long ago and both the iframe and plugin solution don't seem work anymore.:

嵌入带有侧面列表托盘的youtube播放列表

答案中的示例似乎已经过时了,此处是功能版本. (当然,全额归功于@Skyrocker)

The example in the answer seems to be outdated, here a functional version. (Full credits to @Skyrocker of course)

推荐答案

TL; DR:您必须使用官方的 Google Youtube API

TL;DR: you'll have to use official Google Youtube API

不幸的是,不可能像使用iframe嵌入式Youtube那样使用相同的简单"方法.为了能够自定义播放列表的外观,您需要执行一些准备步骤:

Unfortunately it's impossible to use the same "easy" approach, like the one that you use with a iframe embedded Youtube. To be able to customize the look of the playlist you need to do a few preparation steps:

  1. 创建一个Google开发人员帐户以接收所需的API.
  2. 创建一个项目
  3. 凭据页面- OAuth同意屏幕标签上填写必填字段,然后将您的站点域添加到授权域部分(出于测试目的,添加 https://cdpn.io ,但请不要忘记稍后将其替换为您的实际站点域)
  4. 再次转到凭据页面-创建一个API密钥,将其限制为仅使用Youtube Data API(在列表的最底部)
  5. 再次转到凭据页面-创建一个OAuth ClientId.出于测试目的,将 https://cdpn.io 域添加到授权的JavaScript起源,但不要忘记稍后将其替换为您的实际站点域.
  6. 为YouTube启用API服务
  7. >
  1. Create a google developer account to receive the needful API.
  2. Create a project
  3. On the credentials page - on the tab OAuth consent screen fill the required fields and add your site domain into Authorized domains section (For testing purposes add a https://cdpn.io, but don't forget to replace it with your actual site domain later)
  4. Go again to the credentials page - create an API key, restrict it to use only the Youtube Data API (at the very bottom of the list)
  5. Go again to the credentials page - create an OAuth ClientId. For testing purposes add a https://cdpn.io domain to the Authorized JavaScript origins, but don't forget to replace it with your actual site domain later
  6. Enable the API Services for Youtube

然后,在完成此列表中的所有操作之后,请参见 codepen示例如何进行整理.一些要求:

Then, after doing all from this list, see the codepen example how to orchestrate this. A few requirements:

  • 填充API密钥变量
  • 基于Google API的实施需要用户进行确认才能访问服务.您可以根据流程何时初始化此确认弹出消息.
  • Fill API keys variables
  • The implementation, that built on the Google API, will require the confirmation from user to access the services. This is up to you to think of the flow when to initialize this confirmation pop.

更新:

确实,您是对的,这些方法可以在不使用auth的情况下调用.

Indeed, you were right, those methods can be invoked without auth.

此处是列表的升级版本

这篇关于如何使用侧边栏嵌入youtube播放列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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