我正在使用带有IMA扩展的ExoPlayer 2.7.3
。我必须在一定的时间间隔内播放广告。我已经成功地集成了AdsLoader
和AdsMediaSource
。我正在接收和展示广告。但广告只出现在电影的开头。当我想要广告的时候,我该如何制作广告。每隔30分钟)?
发布于 2018-04-21 00:25:39
我不确定您是将IMA扩展与ImaAdsLoader一起使用,还是使用AdsLoader的自定义实现,后者是核心库的一部分(不需要IMA扩展):
使用IMA广告标签
如果使用IMA扩展,则需要创建带有IMA/DoubleClick (样品标签)广告标记的样品标签:
new ImaAdsLoader(this, adTagUri);
标签指向一个VMAP/VAST文件,该文件定义了广告播放的时间。因此,使用此解决方案,您不能告诉播放器的位置的广告编程。相反,所有这些信息都是从广告标签中加载的。
自定义AdsLoader实现
您可以创建自己的AdsLoader
实现,可以将其传递给构造函数或AdsMediaSource,而不是IMA版本。然后,AdsMediaSource
将调用ads加载程序的attachPlayer(player, eventListener, adUiViewGroup)
方法。第二个param是一个AdsLoader.EventListener
,可以用它通知AdsMediaSource
广告加载器的状态。
如果此时您已经掌握了广告的信息以及在哪个位置播放这些广告,那么您只需在连接到播放器时给听众打一次电话:
// create playback state with two ad groups (at 0 and 30 seconds)
AdPlaybackState adPlaybackState = new AdPlaybackState(0, 30 * C.MICROS_PER_SECOND);
// add the uri of the first ad of the first ad group
adPlaybackState = adPlaybackState.withAdUri(0, 0, mp4UriWithAd);
// add the uri of the first ad of the second ad group
adPlaybackState = adPlaybackState.withAdUri(1, 0, mp4UriWithAd);
// add the uri of the second ad of the second ad group
adPlaybackState = adPlaybackState.withAdUri(1, 1, mp4UriWithAd);
// pass to AdsLoader.EventListener
eventListener.onAdPlaybackState(adPlaybackState);
但是,您可能需要先从网络加载广告信息。在这种情况下,当您检索到有关广告的新信息时,您只需更新播放状态。只需再次调用onAdPlaybackState
进行更新即可。
https://stackoverflow.com/questions/49871348
复制相似问题