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
The midroll position is defined in the data of your ad tag uri (at 15 seconds in the example you provided).
If your question is related to configure the server to generate these ad tags, that goes beyond what we can answer here. I suppose the server should know the content duration before generating ad tags for it. @andrewlewis may be able to clarify if that's wrong.
If the problem is that you don't control the content but need to know the duration before constructing the AdsMediaSource, then it's just not possible without loading at least some part of the media. We plan to release a metadata extractor some time soon which helps you with that. Until then, you can just prepare the media without ads in the background and wait until the duration becomes known.
@tonihei This is my use case:
Our Ad server and content server is separate, the ad server can't get the content duration advance. the ad server only provide the pre_ad ,mid_ad,post_ad 's url and duration. Where to insert the mid_ad
is decided by the player. But we can't new the AdPlaybackState if we don't known the mid_ad insert position.
This is my test code:
I used a FixedAdsLoader that configure the play ads from given URLs known in advance. I just use the C.TIME_UNSET as the mid_ad place holder
// init the ad playback state with adGroupTimesUs
adPlaybackState = new AdPlaybackState(0, C.TIME_UNSET);
// add the uri of the first ad of the pre_ad group
adPlaybackState = adPlaybackState.withAdUri(0, 0, Uri.parse("www.xxx.com/test.m3u8"));
// add the uri of the first ad of the mid_ad group
adPlaybackState = adPlaybackState.withAdUri(1, 0, Uri.parse("https:www.xxx.com/dizzy.mp4"));
// pass to AdsLoader.EventListener
updateAdPlaybackState();
prepare the media without ads in the background and wait until the duration becomes known.
when onTimelineChanged() the content duration is known, we update the mid_ad group timeUS.
Modifying the code like this, we are not sure if it will affect the playback process of the player. Help you give some advice.
questions:
If the mid_ad insert position is less than the player buffer position.Will it cause problems?
Using C.TIME_UNSET as the ad group position is probably not a good idea because we don't support that in the player. Also, we currently don't support changing the ad position dynamically. However, we are planning to add support for this soon anyway and we can use this issue to track this.
Besides that, you could try to wrap the content source in a another media source which lets you access the content timeline: new AdsMediaSource(new WrapperSource(contentMediaSource), ...)
The wrapper source can implemented similar to the deprecated ImaAdsMediaSource but with a custom callback or access method to the timeline of content source. That allows you to wait until the content timeline is ready (but before the final timeline is published) and to create the AdPlaybackState only then.
@tonihei As you said, i custom a wrapper source to container the content media source.
@OverRide
public void onSourceInfoRefreshed(MediaSource source, Timeline timeline, Object manifest) {
Assertions.checkArgument(timeline.getPeriodCount() == 1);
long durationUs = timeline.getWindow(0,new Timeline.Window()).durationUs;
if (durationUs != C.TIME_UNSET){
Log.e(TAG,"the content duration = [" + durationUs + "]");
refreshSourceInfo(timeline, manifest);
}else {
// wait the content duration
Log.e(TAG,"the content duration has not known");
}
}
#######
In the callback {onSourceInfoRefreshed}, The HLS format could get the durations when the callback was called, but the mp4 format could get the duration. Is there any way to get the ExtractMediaSource duration ?
changed the title [-]Question: Before the content has been played, I can't get the duration of the content,how to decide the mid ad insert position? [/-][+]Support changing ad break positions[/+]on Feb 8, 2019
Activity
tonihei commentedon Nov 7, 2018
The midroll position is defined in the data of your ad tag uri (at 15 seconds in the example you provided).
If your question is related to configure the server to generate these ad tags, that goes beyond what we can answer here. I suppose the server should know the content duration before generating ad tags for it. @andrewlewis may be able to clarify if that's wrong.
If the problem is that you don't control the content but need to know the duration before constructing the AdsMediaSource, then it's just not possible without loading at least some part of the media. We plan to release a metadata extractor some time soon which helps you with that. Until then, you can just prepare the media without ads in the background and wait until the duration becomes known.
Romantic-LiXuefeng commentedon Nov 7, 2018
@tonihei This is my use case:
Our Ad server and content server is separate, the ad server can't get the content duration advance. the ad server only provide the pre_ad ,mid_ad,post_ad 's url and duration. Where to insert the mid_ad
is decided by the player. But we can't new the AdPlaybackState if we don't known the mid_ad insert position.
This is my test code:
// init the ad playback state with adGroupTimesUs
adPlaybackState = new AdPlaybackState(0, C.TIME_UNSET);
// add the uri of the first ad of the pre_ad group
adPlaybackState = adPlaybackState.withAdUri(0, 0, Uri.parse("www.xxx.com/test.m3u8"));
// add the uri of the first ad of the mid_ad group
adPlaybackState = adPlaybackState.withAdUri(1, 0, Uri.parse("https:www.xxx.com/dizzy.mp4"));
// pass to AdsLoader.EventListener
updateAdPlaybackState();
Modifying the code like this, we are not sure if it will affect the playback process of the player. Help you give some advice.
questions:
If the mid_ad insert position is less than the player buffer position.Will it cause problems?
tonihei commentedon Nov 7, 2018
Thanks for the clarification.
Using C.TIME_UNSET as the ad group position is probably not a good idea because we don't support that in the player. Also, we currently don't support changing the ad position dynamically. However, we are planning to add support for this soon anyway and we can use this issue to track this.
Besides that, you could try to wrap the content source in a another media source which lets you access the content timeline:
new AdsMediaSource(new WrapperSource(contentMediaSource), ...)The wrapper source can implemented similar to the deprecated
ImaAdsMediaSourcebut with a custom callback or access method to the timeline of content source. That allows you to wait until the content timeline is ready (but before the final timeline is published) and to create the AdPlaybackState only then.Romantic-LiXuefeng commentedon Nov 8, 2018
@tonihei As you said, i custom a wrapper source to container the content media source.
@OverRide
public void onSourceInfoRefreshed(MediaSource source, Timeline timeline, Object manifest) {
Assertions.checkArgument(timeline.getPeriodCount() == 1);
long durationUs = timeline.getWindow(0,new Timeline.Window()).durationUs;
if (durationUs != C.TIME_UNSET){
Log.e(TAG,"the content duration = [" + durationUs + "]");
refreshSourceInfo(timeline, manifest);
}else {
// wait the content duration
Log.e(TAG,"the content duration has not known");
}
}
#######
In the callback {onSourceInfoRefreshed}, The HLS format could get the durations when the callback was called, but the mp4 format could get the duration. Is there any way to get the ExtractMediaSource duration ?
tonihei commentedon Nov 8, 2018
Not yet, sorry. This is an enhancement currently tracked by #4727.
[-]Question: Before the content has been played, I can't get the duration of the content,how to decide the mid ad insert position? [/-][+]Support changing ad break positions[/+]Support changing ad break positions.
christosts commentedon Aug 9, 2021
Closing issue as it has been marked fixed in 08fb7bd. The commit will be included in release 2.15.0