Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to know whether an IMA ad being played is Pre-roll, Mid-roll, Post-roll? #5925

Closed
rs146 opened this issue May 21, 2019 · 6 comments
Assignees
Labels

Comments

@rs146
Copy link

rs146 commented May 21, 2019

Content Description

I would like to find out if there is a way to know if the ad currently being played is Pre-roll, Mid-roll or Post-roll. I can't seem to find a listener that exposes this information.
I am currently using the IMA ads event listener on the ImaAdsLoader:

imaAdsLoader.addCallback(VideoAdPlayer.VideoAdPlayerCallback);

ExoPlayer Version

2.9.2

@rs146 rs146 changed the title Is there a way to know total number of ad groups in an IMA ad? Is there a way to know whether an IMA ad being played is Pre-roll, Mid-roll, Post-roll? May 21, 2019
@google google deleted a comment from google-oss-bot May 21, 2019
@andrewlewis
Copy link
Collaborator

Sorry for being slow to reply. The easiest way is probably via the player API: if player.isPlayingAd() returns true, you can get the ad group time via player.getCurrentTimeline().getAdGroupTimeUs(player.getCurrentAdGroupIndex()); a returned value of 0 means a preroll is playing, C.TIME_END_OF_SOURCE means a postroll is playing and any other value indicates a midroll.

@rs146
Copy link
Author

rs146 commented Jul 25, 2019

Hi @andrewlewis ,
I can't see a method called getAdGroupTimeUs() in the Timeline. How can I access this? I've upgraded ExoPlayer to the latest version as well but this method does not exist.

@andrewlewis andrewlewis reopened this Jul 25, 2019
@andrewlewis
Copy link
Collaborator

Sorry, please try: player.getCurrentTimeline().getPeriod(player.getCurrentPeriodIndex(), new Timeline.Period()).getAdGroupTimeUs(player.getCurrentAdGroupIndex()) -- the method is on Timeline.Period not Timeline.

@rs146
Copy link
Author

rs146 commented Jul 25, 2019

Hi @andrewlewis,

This works for pre-roll and mid-roll ads. However with post roll ads, it crashes with the following stack trace. (I'm using DASH with widevine DRM).

Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=-1
        at com.google.android.exoplayer2.Timeline$Period.getAdGroupTimeUs(Timeline.java:402)

To produce this crash I'm using the following code:

Timeline timeline = playerView.getPlayer().getCurrentTimeline();
Timeline.Period period = timeline.getPeriod(playerView.getPlayer().getCurrentPeriodIndex(), new Timeline.Period());

long adGroupTime = period.getAdGroupTimeUs(playerView.getPlayer().getCurrentAdGroupIndex());

@andrewlewis
Copy link
Collaborator

Are you sure player.isPlayingAd() returned true at the moment you run that code?

I tried to reproduce using one of the sample ad tags with a postroll in the demo app, but the ad group index was correct and the associated ad group time was C.TIME_END_OF_SOURCE as expected.

@rs146
Copy link
Author

rs146 commented Jul 26, 2019

Hi @andrewlewis,

Yes - you are correct. I need to use something like this to determine if the player is playing an ad:

public void onPositionDiscontinuity(int reason) {
        if (reason != DISCONTINUITY_REASON_SEEK) {
            adIsPlayingState.onNext(player.isPlayingAd());
        }
    }

The only problem with this is that is does not fire for pre-rolls which is why I have used the VideoAdPlayer.VideoAdPlayerCallback#onPlay() to determine if an ad is playing (as it fires the event for Preroll, Midroll and Postroll ads). When we use the VideoAdPlayer.VideoAdPlayerCallback#onPlay() to determine if an ad is playing, then we experience this crash.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants