我使用的videojs-playlist插件沿着与谷歌的videojs-ima插件.一切工作顺利,除了我只得到一个预加载广告之前的第一个视频.我想在播放列表中的 * 每个 * 视频前一个.基本设置是样板,但供参考:
this.player = videojs('currentvideo', { autoplay : true, fluid : true });
this.player.playlist(this.playlist);
this.player.playlist.autoadvance(5);
const skippable_linear = {google's test ad};
const options = {
id: 'currentvideo',
adTagUrl: skippable_linear,
debug : true
};
this.player.ima(
options
);
this.player.ima.requestAds();
字符串
我尝试过从“结束”事件处理程序中手动调用广告的各种方法,例如再次调用requestAds
:
const _this = this;
this.player.on( 'ended', function(){
/* some other stuff */
_this.player.ima.requestAds();
});
型
这 * 确实 * 在我想要的地方播放广告,但是
1.这打破了播放列表的“自动前进”设置(下一个视频不开始播放时,广告完成),和
1.这使播放器进入“广告显示”模式(擦除器不可用等)。
有没有一种简单的方法可以编程地说“现在播放广告”?我试过,没有快乐,使用ima插件和它所依赖的contrib-ads插件提供的所有看似适用的方法。我承认这是我第一次不得不处理运行广告的视频,所以我有点菜鸟。
3条答案
按热度按时间j2datikz1#
我试图做同样的事情。就像你一样,我在事件上调用
player.ima.requestAds()
时失败了。我挖得更深,我能想到的最好的就是我在下面分享的。根据videojs-ima API,你必须使用
setContentWithAdTag
方法来切换播放器内容。在我们的例子中,它是player.playlist.next
方法。我将videojs-ima examples中的代码与原始的
playlist.next
结合起来,编写了自己的next
。然后我非常残忍地覆盖了原来的插件方法。
下面是代码:
字符串
您可能需要覆盖其他更改当前播放的方法,如
playlist.previous
。我使用
videojs-playlist-ui
,所以在我的情况下,需要更改名为switchPlaylistItem_
的onclick处理程序。我使用了一些很好的旧蛮力来这样做:型
PlaylistMenuItem
的原型应该在 * 初始化播放器之前 * 修改。这个解决方案是有效的,但感觉很黑客,所以如果有人能想出更干净的东西,请分享!
mwecs4sa2#
最后我派生了
videojs-playlist
,并添加了覆盖player.src
方法的选项。请随意使用它:fw-videojs-playlist
关于如何使用它的详细信息都在github readme中(包括一个
ima.setContentWithAdTag
示例)rjee0c153#
我可以成功地做到这一点,
字符串
你只需要听
beforeplaylistitem
类似这样的工作:
型