Android-youtube-player: Detect when an ad is playing and ended

Created on 25 May 2018  路  11Comments  路  Source: PierfrancescoSoffritti/android-youtube-player

Is there a way to detect when an ad starts, and when an ad ends? The PLAYING state is called when an ad starts playing, but we want to know when the actual video starts playing after te ad. @PierfrancescoSoffritti can you cook up some magic for this functionality? Related to #118

enhancement

Most helpful comment

Thanks, I'm going to do some testing during the weekend, hopefully :)

All 11 comments

Hi, do you actually get ads with this player? it never happened to me, I was starting to believe they where disabled in the web player (for some unknown reason).

Unfortunately the IFrame API doesn't offer any way for knowing if an ad is being played, therefore there's not much I can do at the moment :\

I've got the same problem, so i've studied the playerstate when an ads is playing and it follow a regular pattern :

First the player state changed to: (UNDEFINED) because an ads it's loading and for the player this is a undefinded behaviour then player state changed to: (CUED) because it's save the current floating second and previous state of player, finally the player state changed to: (PAUSED)

So for detect and ads i make a function based on videoID that collect state for the current video id and if they are one behind the other (Undefined-Cued-Paused) i know that an ads is playing.

But i know that it's not an elegant solution and i'm looking for something better.

Hey @Trusted97, thanks for the help! Have you found a way to show ads consistently? I never see them in the sample app. Therefore it's not easy for me to do any ads-related testing.

Yeah, i've simply upload a video on youtube full of ads, you can add any
ads you want in video

could you send me the url?

Sure i'll send you asap

Unfortunately, the video I used to test is for some reason free of ads. But I found this video replaceable with ads every 5 minutes :)

Thanks, I'm going to do some testing during the weekend, hopefully :)

I like the player you build very much. It fits very well to a project that I am working. But only after the implementation, I realised that the ads do not apperars really. This is impeditive for me.
Have you found a solution?
Greetings from Brazil.

Ads are controlled by the IFrame API, not by my library. There's not much to do unfortunately.

hello team , can you suggest a proper method for checking of ad is playing or not @PierfrancescoSoffritti

Was this page helpful?
0 / 5 - 0 ratings