google / ExoPlayer

An extensible media player for Android
Apache License 2.0
21.64k stars 6k forks source link

Support ad insertion in multi-period timelines #3693

Open NesmaNasr opened 6 years ago

NesmaNasr commented 6 years ago

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 commented 6 years ago

@andrewlewis , any updates regarding this issue?

andrewlewis commented 6 years ago

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

andrewlewis commented 6 years ago

3452 is related.

victorraft commented 5 years ago

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:

andrewlewis commented 5 years ago
ppodgorski commented 4 months ago

@andrewlewis Do you have any updates regarding this issue?

marcbaechinger commented 4 months ago

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.

ppodgorski commented 4 months ago

@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="
}
marcbaechinger commented 4 months ago

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.