The IMA SDK loads dependencies to request ads, measure viewability and report ad impressions. By initializing IMA before you make an ad request, you maximize the time to load IMA dependencies before ad playback. This page covers how to handling IMA load times in your app.
Call ImaSdkFactory.initialize()
The
ImaSdkFactory.initialize()
method starts to preload SDK resources in advance of the first ad request. To
use initialize()
, you need IMA version 3.35.1 or higher.
Call ImaSdkFactory.initialize()
on application startup, or as early in the
application's lifecycle as your app structure allows. The initialize()
call
takes the following parameters:
context
: Uses the application context, which is always available during the lifecycle of the application.settings
: Pass the anImaSdkSettings
object with its values set. The IMA settings used in theinitialize()
call must be the same as the settings values used in thecreateAdsLoader()
call. The IMA SDK utilizes these settings, particularly the language setting, for cache key. We don't recommend using test or fake values for the settings used in theinitialize()
method call, as cache misses might occur and increase ad load time.
Reuse the AdsLoader
instance
To improve IMA load time, we recommend you reuse the same
AdsLoader
instance. The AdsLoader
interface can handle multiple ad or stream requests.
Avoid creating a new AdsLoader
instance for each request. Creating a new
AdsLoader
instance requires a load time, and uses additional device resources.
Handle load time with the ExoPlayer-IMA extension
Apps using the
ExoPlayer-IMA extension
recreate an AdsLoader
instance on every ad load. The initialize()
call
expedites the first ad request of the AdLoader
. To expedite the first ad
request for new activities, call initialize()
again at the start of the new
activity.
Request ads early
If have access to the AdsLoader
instance prior to starting ad playback, you
can also call the
AdsLoader.requestAds()
method early. Making this call starts loading pre-roll ads. When the user
is ready to start content playback, call the
AdsManager.init()
method and wait for the LOADED
event to play ads.