Search code examples
androidyoutube-apiandroid-youtube-api

YouTube Android Player API - Programatically perform a click on "skip ad"


Intro

I'm working in an android app that receives commands through http network commands (not through touch).

What I need to accomplish

I want to be able to, whenever a user instructs via http command that wants to perform a click on the skip add, programmatically instruct the youtube-player (embedded in my app), to skip the add.

Looking to the available functions I only can check if the player is showing the advertising or not, but nothing related to being able to skip it through a method.

How I'm trying to solve it

I'm trying to go via:

  1. Get all child views and their childs of the activity
  2. Figure out the view that I need to perform the click
  3. Perform the click through view.performClick()

My problem is that it rarely shows advertising, meaning that I'm unable to complete the task or even know if this will work in a useful time.

Any ideas that can help to solve the main problem?

Thanks in advance.


Solution

  • Ideally, Google can provide an api call that can allow skip ad as it is displayed on the screen "You can skip ad in 5, 4, 3, 2, 1s".

    For the TV set top boxs, it has the same problem too. It is common for them not having a mouse, so you cannot move the cursor to the "skip ad" button and click.

    My solution is to create a simulated touch event as you can find from this discussion: How to simulate a touch event in Android?.

    The trick will be in calculating the x , y for the "skip ad" button though.