videojs-ima: Unexpected invocation to startLinearAdMode
Hi, there is a bug with the PlayerWrapper
class.
The bug occurs when you try to load a pre-roll ad that takes more than the time specified in the prerollTimeout setting to load.
The problem is that when the adtimeout
event is triggered and then the adsready
event is triggered, the pre-roll ad is displayed but UI is not updated to reflect that. For example, the vjs-ad-playing
is not added to the player and the content playback is not resumed after pre-roll is ended.
The bug is caused because in the method onAdBreakStart
the videojs-contrib-ads startLinearAdMode
function is called, even if the adtimeout
event was fired before.
This causes a WARN: ‘Unexpected startLinearAdMode invocation (Preroll)’, so this is an unexpected behavior for videojs-contrib-ads.
An easy way to reproduce this is set prerollTimeout
in contribAdsSettings
to a small value like 10.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 17 (3 by maintainers)
Hi, @GavinThompson. In my case I can fix my specific problem adding this workaround to my code. Check it out! I could be good for you, too.
I’ve managed to get it working in two ways.
Downgrading videojs-contrib-ads to version 6.0.0. I can confirm this problem started happening somewhere between 6.0.1 and 6.1.0.
I’ve also managed to get it working by adding a check on
SdkImpl.prototype.onPlayerReadyForPreroll
to check if the player is not in resuming state, as it seems videojs-contrib-ads ask for it now, and also implicitly calling a resume/play function on videojs-contrib-adsendLinearAdMode()
functions. However, this last option wouldn’t play ads if they loaded after the player was already resuming (unless you increased your prerollTimeout). And it seemed to happen quite a lot, so I stick with the first method.There was also a secondary problem which seemd to happen. When the HLS was resuming from ads, it seemed to get stuck on loading sometimes. The main .m3u8 playlist was being fetched, but not the .ts segments.
I’ve managed to fix it by adding a play event on
adend
. As such:Workaround 1: Use
https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-ads/6.0.0/videojs-contrib-ads.js
instead.Workaround 2 (recent versions):
In
videojs.ima.js
, change:To
In
videojs-contrib-ads.js
, wherever there is aendLinearAdMode()
function, add this to the end:You may want to increase your prerollTimeout in player.ima options too.