You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I already opened a question ticket (#5925) with regards to determining Pre-roll, Mid-roll and Postroll ads and since the answer(s) provided there are sufficient for that topic, I have decided to create a new general question.
I have had a look at Google's IMA documentation for getting the duration of an ad.
In addition, I have also looked at getting the duration of an ad by using player.getContentDuration() - however this gives the total duration of the media rather than the individual ad duration.
[REQUIRED] Question
As from my previous discussion, I am using IMA ads in my player. To know when an ad is being played, I am implementing the VideoAdPlayer.VideoAdPlayerCallback from Google's IMA library. For midroll ads in the sample app, when I call this: (ImaAdsLoader) adsLoader).getAdProgress().getDuration();
I get a true duration of the ad (i.e. 10 seconds).
However, with both preroll and postroll ads when I call: (ImaAdsLoader) adsLoader).getAdProgress().getDuration();
it returns with -0.001.
I have 2 questions:
Is there a way to get the correct duration of IMA ads for both preroll and postroll ads?
Why does calling player.isPlayingAd() return false for the postroll ad given that the VideoAdPlayer.VideoAdPlayerCallback#onPlay() callback has been fired?
It's probably easier and more reliable to use ExoPlayer's API rather than VideoAdPlayerCallback, by listening for onPositionDiscontinuity and onTimelineChanged like this:
@Override
public void onPositionDiscontinuity(@DiscontinuityReason int reason) {
logAdStatus();
}
@Override
public void onTimelineChanged(Timeline timeline, @TimelineChangeReason int reason) {
logAdStatus();
}
private void logAdStatus() {
boolean isPlayingAd = player.isPlayingAd();
if (isPlayingAd) {
if (player.getDuration() == C.TIME_UNSET) {
// We don't know the duration yet.
return;
}
int adGroupIndex = player.getCurrentAdGroupIndex();
long adGroupTimeUs = player.getCurrentTimeline()
.getPeriod(player.getCurrentPeriodIndex(), new Period())
.getAdGroupTimeUs(adGroupIndex);
String adType = adGroupTimeUs == C.TIME_END_OF_SOURCE ? "postroll"
: adGroupTimeUs == 0 ? "preroll" : "midroll";
Log.w("DEBUG", "Currently playing " + adType
+ " ad at index " + player.getCurrentAdIndexInAdGroup()
+ " in ad group with index " + player.getCurrentAdGroupIndex()
+ " with duration " + player.getDuration());
} else {
Log.w("DEBUG", "Currently playing content");
}
}
If you want to trigger a single event when starting to play the ad once the duration is known you will need to store some state and de-duplicate the events.
The IMA callbacks and ExoPlayer state can't be perfectly synchronized I'm afraid, but we should be exposing the information you need via the player API. Please let me know if this is still a problem for something you need to do and we can investigate further.
[REQUIRED] Searched documentation and issues
I already opened a question ticket (#5925) with regards to determining Pre-roll, Mid-roll and Postroll ads and since the answer(s) provided there are sufficient for that topic, I have decided to create a new general question.
I have had a look at Google's IMA documentation for getting the duration of an ad.
In addition, I have also looked at getting the duration of an ad by using
player.getContentDuration()
- however this gives the total duration of the media rather than the individual ad duration.[REQUIRED] Question
As from my previous discussion, I am using IMA ads in my player. To know when an ad is being played, I am implementing the
VideoAdPlayer.VideoAdPlayerCallback
from Google's IMA library. For midroll ads in the sample app, when I call this:(ImaAdsLoader) adsLoader).getAdProgress().getDuration();
I get a true duration of the ad (i.e. 10 seconds).
However, with both preroll and postroll ads when I call:
(ImaAdsLoader) adsLoader).getAdProgress().getDuration();
it returns with
-0.001
.I have 2 questions:
player.isPlayingAd()
returnfalse
for the postroll ad given that theVideoAdPlayer.VideoAdPlayerCallback#onPlay()
callback has been fired?A full log report captured from the device
Link to test content
For this test, I used the following code in my media.exolist.json:
I also changed the
PlayerActivity
in the demo app to implement theVideoAdPlayer.VideoAdPlayerCallback
interface.In the
createAdsMediaSource()
method, I have added the following line:I have overridden the
onPlay()
method from theVideoAdPlayer.VideoAdPlayerCallback
as follows within the updatedPlayerActivity
:Tested on sample code versions 2.9.2 and 2.10.3
The text was updated successfully, but these errors were encountered: