avetisk
avetisk

Reputation: 12319

YouTube iFrame API: events fired for TrueView InStream Ads (video ads)

Which events are fired when a TrueView InStreams ad starts and ends?

The YouTube iFrame API reference does not give any hint about it.

I need to know when the real video starts.

As these ads are shown "randomly", I cannot make any test.

One possible answer could be a way to systematically show these ads (and thus allow testing).

Upvotes: 3

Views: 929

Answers (1)

avetisk
avetisk

Reputation: 12319

Seems already answered by What is the YouTube's PlayerState during pre-roll ad?.

Basically, when ads starts state changes from -1 (undefined) to 5 (cued) then 2 (paused).

I guess it's possible to know if ads on by looping (setInterval and such) and checking if state strictly goes from -1, 5 and finally 2.

Starting check with -1 secures from confusing ad's start/end from other event likes "cueing next video", etc.

However, this isn't a perfect solution as ads can start at the end of the video...

Upvotes: 1

Related Questions