插播广告
#
Step-1:Integration Reference- Starting from V9.3.0.1, TP supports the in-stream video ad of Google Ad Manager(GAM).In-stream ads are also called in stream video ad, pre-roll ads, and generally appear before the video is played.
- Ads play in a separate video player positioned on top of the app's content video player. Refer to the picture below:
- Create an ad display container when requesting the ads.
#
NOTES- Note: Don't perform the retry loading method ad in
onAdFailed
callback – it'll cause a lot of useless requests and could make your app run slowly. - TPMediaVideo should be in loadAd() or Start() in main thread.
- The in-stream video will pause to play after your app is running background. So you have to control the video status through calling
tpCustomMediaVideoAd.pause()
in onPause() andtpCustomMediaVideoAd.resume()
in onResume() if app switched between foreground and background.
#
Step-2:Load an ad- Creating an ad object
TPMediaVideo
and posting the ad ID as a parameter. - Setting up the listener.
- Posting the container you created as a parameter
- Create a VideoAdPlayerAdapter class with the VideoView, and adapt it to IMA's VideoAdPlayer interface. This class will handle content and ad playback, and will contain the set of methods that a video player must implement to be used by the IMA SDK.For the specific implementation of VideoAdPlayerAdapter, please refer to Demo or IMA documents
#
Step-3:Show the Streaming ad- After the ad is loaded successfully, get the ad cached by the TP, and call the start() method to display the ad.
- To confirm whether the ad has been loaded successfully, you can make use of 'onAdLoaded' or 'isReady()'.
#
Step-4:Register Ad Event Callback- DON'T request any ads in onAdFailed method. Oherwise you might encounter some invalid requests and UI lags in your app.
- V9.7.10.1 Support new Listener
#
Step-5:Other APIs#
5.1 TPMediaVideoAPI | Explanation |
---|---|
isReady() | Check for available ads.true -available |
setCustomParams(Map<String, Object> map) | customized key-value.Call it before loadAd. |
onDestroy() | Release TPMediaVideod object |
#
5.2 TPCustomMediaVideoAdAPI | Explanation |
---|---|
pause() | Pause the video. |
resume() | Resume playing. |
setCustomShowData(Map<String,Object> customShowData) | customized data,call it before ad displaying |
getCustomNetworkObj() | Obtain AdsManager object.AdsManager adsManager = (AdsManager)tpCustomMediaVideoAd.getCustomNetworkObj(); |
onDestroy() | Release IMA object. |
#
5.3 Hide the countdown timer- Default:the countdown timer displayed.
#
5.4 Sets the preferred language for the ad UI- The supported codes can be found in the Localization guide