尝试使用VideoJS,VideoJS-YouTube,VideoJS-Playlist和VideoJS-Playlist-UI

时间:2019-02-07 18:19:14

标签: javascript html youtube video.js playlist

我正在一个网站上尝试创建自定义主题播放列表,以播放YouTube上托管的视频。我已经在网站的另一部分中成功地同时使用了VideoJS和VideoJS-YouTube,但是在介绍VideoJS-Playlist和VideoJS-Playlist-UI之后,我遇到了一些问题。在尝试了几种不同的方式加载YouTube视频之后,似乎没有任何消息来源。但是,我确实有一个播放列表正在渲染,这让我觉得我在实施VideoJS-YouTube时都错了。

这是我的工作示例,没有VideoJS-Playlist和VideoJS-Playlist-UI

Working CodePen Example

OR

<video class="videos-video video-js vjs-default-skin vjs-big-play-centered" controls data-setup='{ "techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "https://www.youtube.com/watch?v=voFRslp8d60"}], "youtube": { "ytControls": 1 } }'></video>

这是我无法使用的示例,使用VideoJS-Playlist和VideoJS-Playlist-UI

Broken CodePen Example

HTML:

<div>
  <video id="current-video" class="video-js vjs-default-skin vjs-big-play-centered"></video>
</div>
<div>
  <div class="vjs-playlist vjs-playlist-vertical vjs-csspointerevents vjs-mouse"></div>
</div>

和JS:

var options = {
    techOrder: ["youtube"],
    youtube: {
        ytControls: 1
    }
};
var player = videojs('current-video', options);

player.playlist([{
    sources: [{
        src: 'https://www.youtube.com/watch?v=voFRslp8d60',
        type: 'video/youtube'
    }]
}]);

player.playlistUi();

如果有一种方法可以使用这两个额外的插件播放YouTube视频,那么我将向您提供任何建议。谢谢!

1 个答案:

答案 0 :(得分:4)

我找到了答案!有趣的是,遵循VideoJS-YouTube的GitHub Page的文档后,我误入了歧途。如果您安装了插件然后将资源视为常规资源,则无需为插件设置特殊属性,而是可以完美地加载视频。 here或下面的代码段提供了如何正确加载的详细示例:

HTML:

<div>
  <video id="current-video" class="video-js vjs-default-skin vjs-big-play-centered" controls></video>
</div>

JS:

var player = videojs('current-video');

player.playlist([{
    sources: [{
        src: 'https://www.youtube.com/watch?v=voFRslp8d60&t=17s',
        type: 'video/youtube'
    }]
}]);