question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can I play ads in the period of

See original GitHub issue

Hello and thanks for your time…

The required fields are below, but here’s a short introduction:

I started to develop a new app - I have to admit that I am new to android app and exoplayer but have experience as a java developer - for an android TV-Box (beelink GT1) that downloads media to a SD Card (short videos of 2 to 10 minutes in length), plays it 24/7 and the playback is interrupted every 10 minutes to play a sequence of adverts no matter what media source is currently playing or at what position the currently played media source is at. It just keeps spamming adverts in a defined rhythm. Streaming the media is not an option since I have to deal with different bandwidths at the different box locations and sometimes even offline operating boxes (therefore the idea to download the media and saving it to the external storage before/while playing it).

My first idea was to create a ConcatenatingMediaSource and take this “playlist” as “contentMediaSource” parameter for my AdsMediaSource. But this lead to the following error:

 E/AndroidRuntime: FATAL EXCEPTION: ExoPlayerImplInternal:Handler
     Process: com.airtango.lpsplayer, PID: 8711
     java.lang.IllegalArgumentException
         at com.google.android.exoplayer2.util.Assertions.checkArgument(Assertions.java:39)
         at com.google.android.exoplayer2.source.ads.AdsMediaSource.onContentSourceInfoRefreshed(AdsMediaSource.java:329)
         at com.google.android.exoplayer2.source.ads.AdsMediaSource.onChildSourceInfoRefreshed(AdsMediaSource.java:303)
         at com.google.android.exoplayer2.source.ads.AdsMediaSource.onChildSourceInfoRefreshed(AdsMediaSource.java:55)
         at com.google.android.exoplayer2.source.CompositeMediaSource.lambda$prepareChildSource$0$CompositeMediaSource(CompositeMediaSource.java:97)
         at com.google.android.exoplayer2.source.-$$Lambda$CompositeMediaSource$ahAPO18YbnzL6kKRAWdp4FR_Vco.onSourceInfoRefreshed(lambda)
         at com.google.android.exoplayer2.source.BaseMediaSource.refreshSourceInfo(BaseMediaSource.java:74)
         at com.google.android.exoplayer2.source.ConcatenatingMediaSource.updateTimelineAndScheduleOnCompletionActions(ConcatenatingMediaSource.java:705)
         at com.google.android.exoplayer2.source.ConcatenatingMediaSource.handleMessage(ConcatenatingMediaSource.java:675)
         at com.google.android.exoplayer2.source.ConcatenatingMediaSource.lambda$fl0myfoK2raBckmHYwV9YTd0eeo(ConcatenatingMediaSource.java)
         at com.google.android.exoplayer2.source.-$$Lambda$ConcatenatingMediaSource$fl0myfoK2raBckmHYwV9YTd0eeo.handleMessage(lambda)
         at android.os.Handler.dispatchMessage(Handler.java:98)
         at android.os.Looper.loop(Looper.java:154)
         at android.os.HandlerThread.run(HandlerThread.java:61)

Google searches brought me to the issue 3750 saying that I …

… can’t compose it with other media sources as ImaAdsLoader’s logic makes assumptions about the player timeline when it handles player events, and these assumptions may be incorrect if the player is actually playing a concatenation.

My case is a bit different though and here I am asking the question…

[REQUIRED] Searched documentation and issues

[REQUIRED] Question

How can I play a series of short video clips of content media in a everlasting loop - I can do that already with ConcatenatingMediaSource and player.setRepeatMode(…) , but now comes the point where I struggle - and interrupt the playback with ads every 5 minutes?

So basically I want my playlist to be interrupted with ads and not the single clips the playlist is built on. I tried my best to explain my situation and I am happy to answer any questions you may have to understand and maybe help me with my problem.

Thanks alreay! Cheers, Clement

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
christostscommented, Oct 11, 2019

Hi @cle-bo

With regards to the question

How can I play a series of short video clips of content media in a everlasting loop - I can do that already with ConcatenatingMediaSource and player.setRepeatMode(…) , but now comes the point where I struggle - and interrupt the playback with ads every 5 minutes?

my understanding is that you have a predefined list of items and want to play an ad at predefined 5 minute intervals. You may achieve this by concatenating a series of ClippingMediaSources for the main content and regular media sources for your ad content:

  • use a ClippingMediaSource to play a specified range of a media source, e.g. the first 5 minutes
  • concatenate a MediaSource for your ad - treat the ad as regular content, don’t use the AdsMediaSource
  • concatenate the next 5 minutes of the main content with a ClippingMediaSource that plays from the 5th minute until the 10th minute
  • and so on

There are two caveats here:

  • by treating ads as regular content, you will not get the ad markers on the progress bar on the UI
  • to be able to clip your content at 5 minute intervals, you need to ensure that each clip begins at a key frame so that transitions are seamless. Otherwise, you will need to adjust your intervals so that the main content is clipped just before a key frame, or you will not have seamless transitions between your ad and main content
0reactions
christostscommented, Nov 5, 2019

@cle-bo it sounds like you have a very controlled environment. Please make sure to re-test anytime you change a parameter on your setup (video/audio formats, device firmware and/or android version).

Closing this as it seems the issue at hand has been answered.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pause or resume your ads - Google Ads Help
Keep in mind​​ You're in control of your ads. You can pause your ads for any period of time that you'd like, and...
Read more >
What Is the Best Time to Run Your Facebook Ads? - Instapage
Instead of clicking “Run ads all the time,” select “Run ads on a schedule.” Now all you have to do is click inside...
Read more >
Running Ads | Twitch Creator Camp
Running Ads · Tell your community a break is coming · Do not front-load or back-load ads · Start with 1-minute of ads...
Read more >
Google announces new Play Store policies around intrusive ...
Better ad experiences (September 30, 2022): In-game ads can be annoying and Google wants to improve on that. This policy will prohibit any...
Read more >
How Ads on Netflix Will Change the Way You Watch - Time
Netflix's new ad-based plan will allow subscribers to cut costs by at ... of ads per hour that will play before and during...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found