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

Investigate discontinuity reason for ad skipping #4768

Closed
andrewger157 opened this issue Sep 3, 2018 · 12 comments
Closed

Investigate discontinuity reason for ad skipping #4768

andrewger157 opened this issue Sep 3, 2018 · 12 comments
Assignees

Comments

@andrewger157
Copy link

Is there a method in ima-extensions to know if the ad in playback is a pre-roll, mid-roll or post-roll?
Thanks

@tonihei
Copy link
Collaborator

tonihei commented Sep 3, 2018

You can query the ad group positions by getting the timeline period with player.getCurrentTimeline().getPeriod(0, new Period()) and then look at period.adPlaybackState.adGroupTimes. If the ad group time is 0, it's a pre-roll ad, if it's C.TIME_END_OF_SOURCE, it's a post-roll ad, and all other values indicate a mid-roll ad.

If the ad is currently playing, you can also check player.getContentPosition() to get the position of the content. This is either 0 for pre-roll, the duration of the content for post-roll or a value inbetween for mid-roll ads.

@tonihei tonihei self-assigned this Sep 3, 2018
@andrewger157
Copy link
Author

Thanks but...
player.getCurrentTimeline().getPeriod(0, new Period()) throw exception "java.lang.IndexOutOfBoundsException"
(player.getCurrentTimeline().getPeriodCount() return 0)

and 'period' in version 2.8.4 does not have a method or variable 'adPlaybackState'

can you give me some more info on why I have the exception?
thanks

@tonihei
Copy link
Collaborator

tonihei commented Sep 3, 2018

The information is not available immediately but only after the ad data has been loaded. Please listen to onTimelineChanged events and check the timeline to see whether the required information is available. Note that initially, before anything is known, the timeline is empty (check for timeline.isEmpty()) and accessing the period with index 0 will throw an IndexOutOfBoundsException.

Sorry for the adPlaybackState - this information is private in the class. Please use period.getAdGroupCount() to get the number of ad groups and period.getAdGroupTimeUs(index) to get the time of a specific ad group.

@andrewger157
Copy link
Author

Thanks for the directions.
I have another problem now. To know the current ad in playing I'm using "player.getCurrentAdGroupIndex()" but in the case of post-roll it returns -1.

is it an error or can I always consider -1 a post-roll?
Thanks

@tonihei
Copy link
Collaborator

tonihei commented Sep 4, 2018

That shouldn't be the case. Are you sure the post-roll is still playing? player.isPlayingAd() should be true if that's the case.

@andrewger157
Copy link
Author

in fact player.isPlayingAd () returns false, I tried to insert the logic both in "onTimelineChanged" and in "VideoAdPlayer.VideoAdPlayerCallback - onPlay" but in the case of post-roll I always have player.isPlayingAd() false.

What is the best callback to track the transition from an advertisement to content and vice-versa?

@tonihei
Copy link
Collaborator

tonihei commented Sep 4, 2018

You need to listen to eventListener.onPositionDiscontinuity for that. The specified reason will be DISCONTINUITY_REASON_AD_INSERTION.

@andrewger157
Copy link
Author

I was also trying 'onPositionDiscontinuity' but it seems to me that it is not always called, while 'onTracksChanged' is called regularly between an ad and the content and vice-versa

@tonihei
Copy link
Collaborator

tonihei commented Sep 4, 2018

onPositionDiscontinuity should always be called. The only exception is that when the transition happens because the timeline changed. In this case only onTimelineChanged will be called.

@andrewger157
Copy link
Author

onPositionDiscontinuity - DISCONTINUITY_REASON_AD_INSERTION is not called when I skip the ad

@tonihei
Copy link
Collaborator

tonihei commented Sep 4, 2018

Yes indeed. As noted above, the transition can also happen as part of a onTimelineChanged event. When you skip the ad, the timeline is changed because the ad is marked as played. And because we suppress reporting discontinuities if the timeline changed, you'll only get this one event.

Admittedly, this is really confusing and I was expecting to receive the onPositionDiscontinuity too in this case. Will have a look whether we should report DISCONTINUITY_REASON_AD_INSERTION as well in such a case. Marking it as an enhancement.

@ojw28 ojw28 removed the question label Oct 15, 2018
@tonihei tonihei changed the title Advertising Type Investigate discontinuity reason for ad skipping Feb 8, 2019
@tonihei tonihei assigned marcbaechinger and unassigned tonihei Mar 1, 2021
@marcbaechinger
Copy link
Contributor

This commit that landed in dev-v2 deprecates the old onPositionDiscontinuity callback in favor of a new version that has two additional parameters for the old and new PositionInfo.

This is relevant for detecting discontinuities that involve ads in the following:

  • the new callback has two additional arguments oldPosition and newPosition of type PositionInfo. The position info contains information about the window, period and position as well as whether the position is within an ad or content period.
  • The reason DISCONTINUITY_REASON_AD_INSERTION has been removed. Transitions from content to ad, ad to content or ad to ad periods are reported with reason DISCONTINUITY_REASON_AUTO_TRANSITION.
  • The reason DISCONTINUITY_REASON_SKIP has been added. It indicates when an ad that was being played has been skipped by the user (in case ad playback is implemented with an AdsMediaSource like the IMA extension does).

@google google locked and limited conversation to collaborators May 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants