androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.7k stars 405 forks source link

Is there any way to do the preloading of the preroll ad in the Media3? #1040

Closed Anas-mirza912 closed 8 months ago

Anas-mirza912 commented 9 months ago

I'm using the IMA ads Extension in ExoPlayer, and I'm facing an issue where ads take some time to load due to internet connectivity or other unforeseen circumstances. To ensure a bufferless video playback experience in Android, I want to precache the IMA ad from the VAST file. While ExoPlayer automatically loads and stores midroll ads in the cache, it doesn't have sufficient time to preload preroll ads. Is there a way to address this issue and precache preroll ads for smoother playback?

tonihei commented 9 months ago

One simple way to address this issue is to call player.prepare() without attaching it to a visible surface yet (or have this surface hidden). Once the player transitions to Player.STATE_READY you know that the ad is available for playback instantly.

There is also ImaAdsLoader.requestAds which you can use to request the ad metadata in advance. This should also speed up the playback start because the player already knows which ad media to load.

Anas-mirza912 commented 9 months ago

Thank you for your response @tonihei . The issue is that after calling player.prepare(), the player takes some time to load the ad. Is there a way to precache the ad on the homepage before playing the video?

tonihei commented 9 months ago

My response above already pointed out two ways to precache the ad (or at least parts of the preparation process) before playback starts. Calling prepare earlier and only showing the output once its ready it probably the most reliable and easiest way.