Stay organized with collections
Save and categorize content based on your preferences.
IMA Android SDK supports fully automated ad playlists. This feature
inserts ad breaks into the content as specified in
Google Ad Manager
when trafficking your ads. It also greatly simplifies the video player code
necessary to support ad breaks, including pre-rolls, mid-rolls and post-rolls.
When trafficking the ads in Ad Manager, it is possible to specify various ad rules
like "always play ad break at the beginning of the content" or "play a one
minute ad break every 30 minutes of content".
When ads are requested, the ad server can return an ad playlist. The SDK
processes the playlist and automatically schedules the ad breaks that have been
specified.
Since Android uses the same video player for both ad and content playback,
if you plan to implement ad rules, you must save the playhead position of your
content when an ad starts, then seek to that position when the ad finishes.
Be sure to implement the VideoAdPlayer interface in your video
player. This ensures that ad breaks are automatically inserted at the
times specified in Ad Manager.
The CONTENT_PAUSE_REQUESTED
and CONTENT_RESUME_REQUESTED
events are used to pause and resume the content when ad breaks are played. Refer
to the relevant API documentation
for details on these events.
Note: When the content has finished playing or
the user has stopped playback, be sure to call
AdsLoader.contentComplete
in order to signal to the SDK that the content is done. The SDK
then plays the post-roll ad break, if one has been scheduled. The
ALL_ADS_COMPLETED event is raised when ALL ad breaks
have been played. In addition, note that content tracking begins when
init() is called and you should always call init()
before playing content.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["\u003cp\u003eIMA Android SDK simplifies video ad integration by automating ad playlist insertion and playback, including pre-rolls, mid-rolls, and post-rolls.\u003c/p\u003e\n"],["\u003cp\u003eAd breaks are scheduled based on rules defined in Google Ad Manager, enabling features like pre-roll ads and periodic mid-rolls.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers must implement the \u003ccode\u003eVideoAdPlayer\u003c/code\u003e interface and manage content position during ad breaks for seamless transitions between ads and content.\u003c/p\u003e\n"],["\u003cp\u003eThe SDK provides events (\u003ccode\u003eCONTENT_PAUSE_REQUESTED\u003c/code\u003e, \u003ccode\u003eCONTENT_RESUME_REQUESTED\u003c/code\u003e) to handle content playback during ad breaks and signals ad completion with \u003ccode\u003eALL_ADS_COMPLETED\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eContent tracking begins with \u003ccode\u003einit()\u003c/code\u003e, which should be called before content playback, and \u003ccode\u003econtentComplete()\u003c/code\u003e should be called after content ends to trigger post-rolls.\u003c/p\u003e\n"]]],[],null,["# Automate ad playlists\n\nIMA Android SDK supports fully automated ad playlists. This feature\ninserts ad breaks into the content as specified in\n[Google Ad Manager](//admanager.google.com/)\nwhen trafficking your ads. It also greatly simplifies the video player code\nnecessary to support ad breaks, including pre-rolls, mid-rolls and post-rolls.\n\n- When trafficking the ads in Ad Manager, it is possible to specify various ad rules like \"always play ad break at the beginning of the content\" or \"play a one minute ad break every 30 minutes of content\".\n- When ads are requested, the ad server can return an ad playlist. The SDK processes the playlist and automatically schedules the ad breaks that have been specified.\n- Since Android uses the same video player for both ad and content playback, if you plan to implement ad rules, you must save the playhead position of your content when an ad starts, then seek to that position when the ad finishes. Be sure to implement the `VideoAdPlayer` interface in your video player. This ensures that ad breaks are automatically inserted at the times specified in Ad Manager. \n\n ```gdscript\n private boolean playingContent = true;\n private int contentPosition = -1;\n private List callbacks =\n new ArrayList();\n\n @Override\n public void addCallback(VideoAdPlayerCallback callback) {\n callbacks.add(callback);\n }\n\n @Override\n public void removeCallback(VideoAdPlayerCallback callback) {\n callbacks.remove(callback);\n }\n\n public void loadContent() {\n playingContent = true;\n load(CONTENT_URL);\n }\n\n @Override\n public void loadAd(String mediaUrl) {\n playingContent = false;\n load(mediaUrl);\n }\n\n public void pauseContent() {\n savePosition();\n pause();\n }\n\n @Override\n public void pauseAd() {\n pause();\n }\n\n private void pause() {\n myVideoView.pause();\n for (VideoAdPlayerCallback callback : callbacks) {\n callback.onPause();\n }\n }\n\n public void resumeContent() {\n loadContent();\n if (contentPosition \u003e 0) {\n restorePosition();\n }\n resume();\n }\n\n @Override\n public void resumeAd() {\n resume();\n }\n\n private void resume() {\n myVideoView.start();\n for (VideoAdPlayerCallback callback : callbacks) {\n callback.onResume();\n }\n }\n\n public void savePosition() {\n contentPosition = myVideoView.getCurrentPosition();\n }\n\n public void restorePosition() {\n myVideoView.seekTo(contentPosition);\n }\n ```\n- The `CONTENT_PAUSE_REQUESTED` and `CONTENT_RESUME_REQUESTED` events are used to pause and resume the content when ad breaks are played. Refer to the relevant [API documentation](/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/AdEvent.AdEventType) for details on these events.\n\n**Note:** When the content has finished playing or\nthe user has stopped playback, be sure to call\n[AdsLoader.contentComplete](/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/AdsLoader#contentComplete())\nin order to signal to the SDK that the content is done. The SDK\nthen plays the post-roll ad break, if one has been scheduled. The\n`ALL_ADS_COMPLETED` event is raised when ALL ad breaks\nhave been played. In addition, note that content tracking begins when\n`init()` is called and you should always call `init()`\nbefore playing content."]]