videojs / videojs-contrib-ads

A Tool for Building Video.js Ad Plugins
http://videojs.github.io/videojs-contrib-ads/
Other
381 stars 257 forks source link

Custom snapshot's currentTime #445

Closed mysuf closed 5 years ago

mysuf commented 5 years ago

My player currently saves time played to continue watching, but I would like to play also preroll before. Now it gets and sets currentTime() on loadedmetadata event which skips preroll (ima sdk evaluates that probably as "expired" when current time misses some time window), but occurs before currentTime is snapshoted so it properly seeks after preroll.

Question: is there way or workaround how to play preroll and also set snapshot's currentTime > 0.0 (offset) ? Thanks

Edit: Just found probably bug in debug mode. When debug is true, it skips preroll/postroll, plays content video, throws adtimeout and preserve loading spinner on top.. With debug off, it behaves as expected.

Edit2: Just found another bug. contrib-ads does not reset properly when adtimeout is pending and source is changed. After contentupdate, it plays preroll but does not switch back to content.. Log:

VIDEOJS: ADS: Play middleware has been registered with videojs VIDEOJS: ADS: Received adsready event (BeforePreroll) VIDEOJS: ADS: Using playMiddleware to block content playback VIDEOJS: ADS: Play call to Tech was terminated. VIDEOJS: ADS: Received play event (BeforePreroll) VIDEOJS: ADS: BeforePreroll -> Preroll VIDEOJS: ADS: Triggered readyforpreroll event (Preroll) VIDEOJS: ADS: contentupdate event VIDEOJS: ADS: skipLinearAdMode (Preroll) //called by integration to cleanup hanging events VIDEOJS: ADS: Received adsready event (Preroll) VIDEOJS: ADS: Triggered readyforpreroll event (Preroll) VIDEOJS: WARN: Unexpected startLinearAdMode invocation (Preroll) VIDEOJS: ADS: adtimeout (Preroll) VIDEOJS: WARN: Unexpected skipLinearAdMode invocation

incompl commented 5 years ago

In your integration, would it work to set player.ads.snapshot.currentTime = time on adstart?

mysuf commented 5 years ago

@incompl The issue with adstart is that it triggers multiple times during content playback and also .one is not solution because there might be no preroll at all.

This is my current integration:

    player.on(['loadedmetadata', 'contentloadedmetadata'] , function() {
        player.one('playing', () => player.currentTime(lastTime||0));
    });

The downside of this solution is that it seeks after preroll so mostly its not buffered and loading spinner shows on top..

incompl commented 5 years ago

It's interesting that you get adstart events during content playback, the only place in videojs-contrib-ads where adstart is triggered is when handling the start of an ad break. Do you know where those other adstarts are coming from?

mysuf commented 5 years ago

@incompl I mean adstart for preroll, each midroll and last for postroll.

incompl commented 5 years ago

Would it work to check player.ads.adType in your adstart handler to verify it's a preroll?

mysuf commented 5 years ago

I'm not sure if there wasnt some event race condition on setting currentTime. I tried many ways but its already some time when I solved it. I'll give a try. Thanks

incompl commented 5 years ago

Got it working? 🤞

mysuf commented 5 years ago

@incompl I'll find out on Monday and let you know (and possibly reopen if not). thx