googleads / videojs-ima

IMA SDK Plugin for Video.js
Apache License 2.0
450 stars 284 forks source link

Which method to call to see if the player "isInAdsMode" #910

Closed MikeSperone closed 4 years ago

MikeSperone commented 4 years ago

I'm handling an edge case in our videojs player where I need to see if we're currently playing an ad.

I got this working by doing check this successfully with this:

if (edgeCaseHappened) {
    if (this.player.ads.isInAdsMode() && !this.player.ads.isContentResuming()) {
        doTheThingAfterTheAd();
    } else {
        doTheThingRightNow();
    }
}

My co-worker brought up the question of whether we should be interacting with these methods and events from videojs-contrib-ads (player.ads) directly, or shouldn't there be a way to do this via videojs-ima?

It's not really documented either way, and I didn't see anything in the src... so I was wondering if there is a player.ima.<something> to check for this case, or if it is recommended to directly use the methods from videojs-contrib-ads

Thanks!

dioramayuanito commented 4 years ago

hi Mike,

we can check it also from player.ima.controller.sdkImpl.adsActive === true

please cmiiw

Kiro705 commented 4 years ago

Hello @MikeSperone ,

I would recommend using the IMA ad events to track whether or not an ad is playing.

You could use either CONTENT_PAUSE_REQUESTED or STARTED to set a boolean to true, then use CONTENT_RESUME_REQUESTED or COMPLETED to set that boolean back to false.

The difference between the two types of events being focused on an entire ad break or individual ads.

Let me know if you have any more questions, to set up ad events with the VideoJS-IMA plugin you can look to the advanced example.