# 8. 激励视频广告

# (1) Api说明

ATRewardedVideo:

API 参数 说明
loadVideoAd string placementid,Dictionary<string,string> extra 加载广告
hasAdReady string placementid 判断是否有广告缓存
showAd string placementid,Dictionary<string,string> extra 显示广告
cleanAd string placementid 清除广告

# (2) 加载激励视频

使用以下代码加载激励视频广告:

public void loadVideo()
{
    if(callbackListener == null) {
        callbackListener = new ATCallbackListener();
        Debug.Log("Developer init video....unitid:" + mPlacementId_rewardvideo_all);
        ATRewardedVideo.Instance.setListener(callbackListener);
    }

    Dictionary<string,string> jsonmap = new Dictionary<string,string>();
    jsonmap.Add(ATConst.USERID_KEY, "test_user_id");
    jsonmap.Add(ATConst.USER_EXTRA_DATA, "test_user_extra_data");

    ATRewardedVideo.Instance.loadVideoAd(mPlacementId_rewardvideo_all,jsonmap);
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

注: 请参阅下文,了解如何获得有关激励视频广告事件的通知(加载成功/失败,展示,点击,视频开始/结束和激励)。

# (3) 展示激励视频

与展示原生广告相比,展示激励视频要简单得多,只要调用展示api并传递展示广告位ID作为参数:

public void showVideo()
{        
    Debug.Log ("Developer show video....");
    ATRewardedVideo.Instance.showAd(mPlacementId_rewardvideo_all);
}
1
2
3
4
5

当用到场景功能时:

public void showVideo()
{
    Debug.Log ("Developer show video....");
    Dictionary<string, string> jsonmap = new Dictionary<string, string>();
    jsonmap.Add(AnyThinkAds.Api.ATConst.SCENARIO, showingScenarioID);
    ATRewardedVideo.Instance.showAd(mPlacementId_rewardvideo_all, jsonmap);    
}

1
2
3
4
5
6
7
8

# (4) 实现激励视频的监听器

您可以实现ATRewardedVideo Listener接口的类,来获得有关激励视频广告事件的通知:

class ATCallbackListener : ATRewardedVideoListener {
    public void onRewardedVideoAdLoaded(string unitId){
        Debug.Log("Developer onRewardedVideoAdLoaded------");
    }

    public void onRewardedVideoAdLoadFail(string unitId, string code, string message){
        Debug.Log("Developer onRewardedVideoAdLoadFail------:code" + code + "--message:" + message);
    }

    public void onRewardedVideoAdPlayStart(string unitId, ATCallbackInfo callbackInfo){
        Debug.Log("Developer onRewardedVideoAdPlayStart------");
    }

    public void onRewardedVideoAdPlayEnd(string unitId, ATCallbackInfo callbackInfo){
        Debug.Log("Developer onRewardedVideoAdPlayEnd------");
    }

    public void onRewardedVideoAdPlayFail(string unitId, string code, string message){
        Debug.Log("Developer onRewardedVideoAdPlayFail------code:" + code + "---message:" + message);
    }

    public void onRewardedVideoAdPlayClosed(string unitId, bool isReward, ATCallbackInfo callbackInfo){
        Debug.Log("Developer onRewardedVideoAdPlayClosed------isReward:" + isReward);
    }

    public void onRewardedVideoAdPlayClicked(string unitId, ATCallbackInfo callbackInfo){
        Debug.Log("Developer onRewardVideoAdPlayClicked------");
    }

    public void onReward(string unitId, ATCallbackInfo callbackInfo){
        Debug.Log("Developer onReward------");
    }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

创建此类的一个实例,并将其传递给加载api中的listener参数.