ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

Support ad insertion in multi-period timelines

Open NesmaNasr opened this issue 7 years ago • 9 comments

Issue description

I need to create playlist of videos to be played in a loop, and 1 pre-roll Ad to be played once in the start of this list, what I did is: ConcatenatingMediaSource concatenatedSource =new ConcatenatingMediaSource(MediaSource[]); LoopingMediaSource loopingSource = new LoopingMediaSource(concatenatedSource); AdsMediaSource adssource = new AdsMediaSource(loopingSource,...............................);

this works fine in case I have only 1 video in the playlist, but in case I have more than 1 I got "IllegalArgumentException" in the ImaAdsLoader.onTimelineChanged() due to the following assertion:

Assertions.checkArgument(timeline.getPeriodCount() == 1);

So is there a way to fix this, or the AdsMediaSource can be used only with 1 track?

Reproduction steps

Just open the player with playlist of size > 1

Link to test content

Not specific url related

Version of ExoPlayer being used

dev-v2 branch

Device(s) and version(s) of Android being used

Nexus 5,6 & 9

A full bug report captured from the device

01-11 14:46:43.654 2793-2793/com.intigral.splive W/System.err: java.lang.IllegalArgumentException 01-11 14:46:43.654 2793-2793/com.intigral.splive W/System.err: at com.google.android.exoplayer2.util.Assertions.checkArgument(Assertions.java:37) 01-11 14:46:43.654 2793-2793/com.intigral.splive W/System.err: at com.google.android.exoplayer2.ext.ima.ImaAdsLoader.onTimelineChanged(ImaAdsLoader.java:671) 01-11 14:46:43.654 2793-2793/com.intigral.splive W/System.err: at com.google.android.exoplayer2.ExoPlayerImpl.updatePlaybackInfo(ExoPlayerImpl.java:588) 01-11 14:46:43.654 2793-2793/com.intigral.splive W/System.err: at com.google.android.exoplayer2.ExoPlayerImpl.handlePlaybackInfo(ExoPlayerImpl.java:541) 01-11 14:46:43.654 2793-2793/com.intigral.splive W/System.err: at com.google.android.exoplayer2.ExoPlayerImpl.handleEvent(ExoPlayerImpl.java:483) 01-11 14:46:43.654 2793-2793/com.intigral.splive W/System.err: at com.google.android.exoplayer2.ExoPlayerImpl$1.handleMessage(ExoPlayerImpl.java:100) 01-11 14:46:43.654 2793-2793/com.intigral.splive W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102) 01-11 14:46:43.654 2793-2793/com.intigral.splive W/System.err: at android.os.Looper.loop(Looper.java:154) 01-11 14:46:43.655 2793-2793/com.intigral.splive W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6077) 01-11 14:46:43.655 2793-2793/com.intigral.splive W/System.err: at java.lang.reflect.Method.invoke(Native Method) 01-11 14:46:43.655 2793-2793/com.intigral.splive W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 01-11 14:46:43.655 2793-2793/com.intigral.splive W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

Thanks

NesmaNasr avatar Jan 11 '18 10:01 NesmaNasr

@andrewlewis , any updates regarding this issue?

NesmaNasr avatar Jan 15 '18 08:01 NesmaNasr

ImaAdsLoader currently doesn't support multi-period timelines like concatenations. Marking as an enhancement.

andrewlewis avatar Jan 15 '18 10:01 andrewlewis

#3452 is related.

andrewlewis avatar Jan 15 '18 11:01 andrewlewis

Hi, @andrewlewis With the limitation of #3750 (not being able to insert AdsMediaSource inside ConcatenateMediaSource) I had to change my approach and tried to do something similar as @NesmaNasr did: playing a single preroll before my videos playlist, by making an AdsMediaSource with a ConcatenateMediaSource inside it, but now I'm facing this new limitation. I believe I am left with no easy way of implementing what I want, so I'll need to take a manual and very messy approach. So I have a few questions:

  • Are these limitations documented anywhere? I don't want to be caught a third time by another new limitation after all my code is implemented.
  • Do you have plans on fixing either this issue or #3750 ?
  • Do you have any advices for me on how to implement what I want?

victorraft avatar Aug 13 '18 19:08 victorraft

  • The javadoc for AdsMediaSource documents the two limitations you're already aware of. I can't think of any other relevant ones.
  • I'd like to address the limitation that prevents concatenation of ads media sources, but don't have time at the moment. So it's planned but please don't rely on it being done soon.
  • For now you'll probably have to go with the manual approach of swapping our the player's source from your app's code. You can probably optimize this a bit by pre-caching the content you want to play so it loads faster (though this will add a bit more complexity).

andrewlewis avatar Aug 28 '18 07:08 andrewlewis

@andrewlewis Do you have any updates regarding this issue?

ppodgorski avatar Mar 05 '24 10:03 ppodgorski

Can you clarify what you are asking for? I'm asking because since that issue was answered I think a few things changed:

ConcatenatingMediaSource

ConcatenatingMediaSource is kind of deprecated because you can do the same now with the playlist API of ExoPlayer. This allows to add multiple media items to the playlist, each of them can have a client-side ad tag for each media item. There is such a playlist example with multiple items each having an ad in the main demo app.

The stack trace in the initial report alludes that this is the case this issue is about and you are asking for.

Support ad insertion in multi-period timelines

Since a while server-side ad insertion has been added that in case of DASH uses multi-period streams to insert ads on the server side. That's another way how ExoPlayer supports multi-period streams/timelines. There are samples in the main demo app for this that you can find here.

Note however, that server-side ad insertion doesn't currently support mulitple DAI ads in the playlist at the same time. So the state of DAI is actually what has been fixed for client-side ads as far as I understand.

multi-period DASH streams with client-side ad insertion

If you are asking for this, which is as far as I can tell closest to the issue title Support multi-period timelines, then I think this is still not supported I'm afraid.

Given this it appears to me that this issue actually can be closed, as it AFAIU technically asks for supporting IMA ads with multiple, single-period timelines in a playlist. This is an available feature as explained above.

marcbaechinger avatar Mar 05 '24 10:03 marcbaechinger

@marcbaechinger thanks for your reply. Actually, I considered creating a new issue, but it would be identical to #8676, which was marked as a duplicate of this one. Therefore, I'm asking for an update here.

You can reproduce this issue by replacing one of IMA sample in the media.exolist.json file with Multi-period DASH:

{
        "name": "VMAP pre-roll",
        "uri": "https://dash.akamaized.net/dash264/TestCases/5a/nomor/1.mpd",
        "ad_tag_uri": "https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/ad_rule_samples&ciu_szs=300x250&ad_rule=1&impl=s&gdfp_req=1&env=vp&output=vmap&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ar%3Dpreonly&cmsid=496&vid=short_onecue&correlator="
}

ppodgorski avatar Mar 05 '24 13:03 ppodgorski

Thanks for clarifying. As mentioned above, multi-period DASH is not supported for client-side ads with the IMA extension. There are no updates around this yet I'm afraid.

marcbaechinger avatar Mar 05 '24 14:03 marcbaechinger

I'm de-duplicating the remaining feature request of supporting client-side ads in multi-period DASH streams to https://github.com/androidx/media/issues/1642 to have it tracked in the Media3 issue tracker.

tonihei avatar Aug 28 '24 12:08 tonihei