Help Center/Details/

Template Draw Video Ads

Introduction

Template rendering Draw: Developers do not need to edit and render the ad style by themselves, they can directly call the relevant interface to get the ad view for display

Supported ad size: vertical video (aspect ratio 16:9)

Note: Developers are not supported to add buttons to the view and block ads

Permission

**Template rendering Draw video ads: ** Provided by default

Template rendering information flow request method (TTNativeExpressAd)

Note: The template ad request method requires the developer to set the setExpressViewAcceptedSize parameter in dp.
If the height is set to 0, the returned view will be highly adaptive according to the different templates checked on the platform.

Create TTAdNative object

//创建TTAdNative对象,createAdNative(Context context) context需要传入Activity对象
TTAdNative mTTAdNative = TTAdSdk.getAdManager().createAdNative(this);

Create ad request AdSlot

AdSlot adSlot = new AdSlot.Builder()
        .setCodeId(codeId) //广告位id
        .setSupportDeepLink(true)
        .setAdCount(1) //请求广告数量为1到3条
        .setExpressViewAcceptedSize(expressViewWidth,expressViewHeight) //期望模板广告view的size,单位dp
        .build();

Parameter description

Parameter description
setCodeId The code ID created by the platform starts with 9 and 9 digits
setAdCount The number of requests is 1-3. It is recommended to set to 1
setExpressViewAcceptedSize Set the size of the request template creative unit: dp

Note: In the parameter setting of the desired personalized template size, the personalized template Draw video ad height cannot be set to 0

Request ads

The access party can call loadExpressDrawFeedAd(AdSlot adSlot, @NonNull NativeExpressAdListener listener) to load ads asynchronously
Note: The click event registration time is before the ad render, otherwise it will affect the display and click data reporting

//加载广告
mTTAdNative.loadExpressDrawFeedAd(adSlot, new TTAdNative.NativeExpressAdListener() {
	//广告加载失败
    @Override
    public void onError(int code, String message) {
    
   	}
	//广告加载成功
    @Override
    public void onNativeExpressAdLoad(List<TTNativeExpressAd> ads) {
        
    }
});

NativeExpressAdListener Description

Callback Description
onError() Advertisement request failed callback The returned error code (code) indicates the reason why the advertisement request failed,详情请见链接
onNativeExpressAdLoad() Callback for successful ad request, the client can call render() in this callback for ad rendering

Ad click event listener

ad.setExpressInteractionListener(new TTNativeExpressAd.ExpressAdInteractionListener() {
		//广告点击的回调
       @Override
       public void onAdClicked(View view, int type) {

       }
	   //广告展示回调
       @Override
       public void onAdShow(View view, int type) {

       }
	   //广告渲染失败
       @Override
       public void onRenderFail(View view, String msg, int code) {

       }
	   //广告渲染成功
       @Override
       public void onRenderSuccess(View view, float width, float height) {
                          
       }
      });

ExpressAdInteractionListener Description

Callback Description
onAdClicked() The callback of the ad click, the action after the click is controlled by the sdk.
onAdShow() Advertisement display callback, display volume can be counted in the method provided by CSJ
onRenderFail() Personalized template rendering failed
onRenderSuccess() The personalized template is rendered successfully, the client can directly add the view of the advertisement to the control to be displayed in the callback

Note: After loading the ad, call the TTNativeExpressAd.render() method to render the ad. In the onRenderSuccess(View view, float width, float height) callback, handle the logic of adding the ad view, width&height is The width and height of the ad.

视频状态监听

/**
* 设置视频广告的回调监听
*/
//点击监听器必须在getAdView之前调用
ad.setVideoAdListener(new TTNativeExpressAd.ExpressVideoAdListener() {
    //视频广告加载成功
    @Override
    public void onVideoLoad() {

    }
	//视频广告加载失败
    @Override
    public void onVideoError(int errorCode, int extraCode) {

    }
	//视频广告播放回调
    @Override
    public void onVideoAdStartPlay() {

    }
	//视频广告暂停回调
    @Override
    public void onVideoAdPaused() {

    }
	//视频广告续播
    @Override
    public void onVideoAdContinuePlay() {

    }
	//视频播放进度
    @Override
    public void onProgressUpdate(long current, long duration) {

    }
	//视频广告播放完成回调
    @Override
    public void onVideoAdComplete() {

    }
	//点击重播
    @Override
    public void onClickRetry() {

    }
});

ExpressVideoAdListener description

Method Description
onVideoLoad() Video ad loaded successfully callback
onVideoError() Video ad loading failed callback
onVideoAdStartPlay() Video ad show callback
onVideoAdPaused() Video ad pause callback
onVideoAdContinuePlay() Video ad rebroadcast callback
onProgressUpdate() Video ad playback progress callback
onVideoAdComplete() Video ad playback complete callback
onClickRetry() Video ad click replay callback

Destroy the ad object

//在Activity的onDestroy回调方法中销毁广告对象
@Override
protected void onDestroy() {
    super.onDestroy();
    if (mTTAd != null) {
        mTTAd.destroy();
    }
}

Reference Demo

For template Draw ads, please refer to the DrawNativeExpressVideoActivity example in Demo

Template rendering Draw Note:

  1. The personalized template Draw ad does not support dislike logic.
  2. In the parameter setting of the template size, the height of the personalized template Draw video advertisement cannot be set to 0
Did the content solve your problem?
Contact us