| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- import { DataEventId, VideoAdType } from "../../../../../game/data/GameData";
- import { zgSingleton } from "../../zgSingleton";
- import ATSDKMgr, { AdPlayStateType } from "./ATSDKMgr";
- /**
- * 激励视频广告
- * @description
- * @author 冯聪
- */
- export class ATRewardVideo extends zgSingleton {
- /** */
- private ATRewardVideoJS: any;
- /** 激励视频状态 */
- public reawardAdState: RewardAdState = 0;
- /** 是否加载完显示 */
- public ifLoadShow: boolean = false;
- /**是否观看完毕 */
- public canGet: boolean = false;
- /** 去重点击状态 */
- private singleClick = false;
- init() {
- this.ATRewardVideoJS = cc["ATRewardVideoJS"];
- this.ATRewardVideoJS.proxy = this;
- this.ATRewardVideoJS.init();
- this.canGet = false;
- if (this.reawardAdState == RewardAdState.Unload) {
- this.loadAd();
- }
- }
- /** 广告位id */
- placementID() {
- if (cc.sys.os === cc.sys.OS_IOS) {
- return ATSDKMgr.topon_rewardVideo_placementId;
- } else if (cc.sys.os === cc.sys.OS_ANDROID) {
- return ATSDKMgr.topon_rewardVideo_placementId;
- }
- }
- //广告逻辑部分------------------------------------------------------------------------
- /** 检测是否准备完毕 */
- hasAdReady() {
- return this.ATRewardVideoJS.hasAdReady();
- }
- /** 加载广告 */
- loadAd() {
- console.log("anythink === 加载激励视频广告", RewardAdState[this.reawardAdState]);
- if (this.reawardAdState == RewardAdState.Loading) {
- return;
- }
- console.log("anythink === 加载激励视频广告 onload", RewardAdState[this.reawardAdState]);
- this.reawardAdState = RewardAdState.Loading;
- this.ATRewardVideoJS.loadAd(gData.loginData.uin, "userDataKey");
- // //test
- // this.ATRewardVideoJS.loadAd("userDataID", "userDataKey");
- }
- /** 显示广告 */
- showAd() {
- if (this.reawardAdState != RewardAdState.LoadSuccess) {
- this.loadAd();
- this.ifLoadShow = true;
- return;
- }
- this.ATRewardVideoJS.showAd();
- }
- //广告回调部分------------------------------------------------------------------------
- /**
- * 激励视频加载完毕
- * @param placementId 广告位id
- */
- onRewardedVideoAdLoaded(placementId: string) {
- // ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")");
- // ATRewardVideo.getInstance().showAd()
- console.log("anythink === 加载激励视频广告成功", this.hasAdReady(), RewardAdState[this.reawardAdState])
- this.reawardAdState = RewardAdState.LoadSuccess;
- if (this.ifLoadShow) {
- this.showAd();
- this.ifLoadShow = false;
- }
- }
- /**
- * 激励视频加载失败
- * @param placementId 广告位id
- * @param errorInfo 错误信息
- */
- onRewardedVideoAdFailed(placementId, errorInfo) {
- // ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
- console.log("anythink === 加载激励视频广告失败", RewardAdState[this.reawardAdState]);
- this.reawardAdState = RewardAdState.LoadFail;
- }
- /**
- * 激励视频开始播放
- * @param placementId 广告位id
- * @param callbackInfo 回调信息
- */
- onRewardedVideoAdPlayStart(placementId, callbackInfo) {
- //ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
- //视频埋点开始
- let data = JSON.parse(callbackInfo);
- gData.adData.updateADLog(4, placementId, data);
- gData.adData.updateData(placementId, data);
- mk.data.sendDataEvent(DataEventId.video_init, mk.ad.videoAdType);
- this.reawardAdState = RewardAdState.Unload;
- let times = mk.storage.getStorage('ad_videoEcpm');
- if (!times) {
- times = 1;
- }
- else {
- times++;
- }
- mk.storage.setStorage('ad_videoEcpm', times);
- if (times <= 300) {
- if (times <= 50) {
- mk.data.sendDataEventValue(DataEventId.ad_videoEcpm, `ad_video_ecpm${times}`, data.adsource_price);
- }
- else if (times % 10 == 0) {
- mk.data.sendDataEventValue(DataEventId.ad_videoEcpm, `ad_video_ecpm${times}`, data.adsource_price);
- }
- }
-
- //点击关闭的时候重新加载(亲测,即使在start这边 加载 也是在点击关闭时候才返回成功)
- //this.loadAd();
- this.singleClick = true;
- }
- /**
- * 激励视频播放完毕
- * @param placementId 广告位id
- * @param callbackInfo 回调信息
- */
- onRewardedVideoAdPlayEnd(placementId, callbackInfo) {
- //ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
- }
- /**
- * 激励视频播放失败
- * @param placementId 广告位id
- * @param errorInfo 错误信息
- * @param callbackInfo 回调信息
- */
- onRewardedVideoAdPlayFailed(placementId, errorInfo, callbackInfo) {
- mk.console.log("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed placementId >> ", placementId);
- mk.console.log("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed errorInfo ", errorInfo);
- mk.console.log("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed callbackInfo ", callbackInfo);
- let data = JSON.parse(callbackInfo)
- gData.adData.updateADLog(5, placementId, data);
- ATSDKMgr.getInstance().watchVideoAdCallBack(AdPlayStateType.PlayFail);
- }
- /**
- * 激励视频点击关闭
- * @param placementId 广告位id
- * @param callbackInfo 回调信息
- */
- onRewardedVideoAdClosed(placementId, callbackInfo) {
- // ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdClosed(" + placementId + ", " + callbackInfo + ")");
- let data = JSON.parse(callbackInfo)
- let request_id = ''
- if (data.ext_info && data.ext_info.request_id) {
- request_id = data.ext_info.request_id
- }
- if (this.canGet) {
- ATSDKMgr.getInstance().watchVideoAdCallBack(AdPlayStateType.WatchEnd,request_id);
- mk.data.sendDataEvent(DataEventId.video_end, mk.ad.videoAdType);
- }
- else {
- ATSDKMgr.getInstance().watchVideoAdCallBack(AdPlayStateType.Cancel);
- }
- this.canGet = false;
- this.loadAd();
- }
- /**
- * 激励视频被点击
- * @param placementId
- * @param callbackInfo
- */
- onRewardedVideoAdPlayClicked(placementId, callbackInfo) {
- // ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
- let data = JSON.parse(callbackInfo)
- gData.adData.updateADLog(51, placementId, data);
- mk.data.sendDataEvent(DataEventId.ad_click, '激励视频点击');
- if (this.singleClick) {
- this.singleClick = false;
- gData.adData.updateADLog(71, placementId, data);
- }
- }
- /**
- * 能获取奖励
- * @description 引擎的自动判断
- * @param placementId 广告位id
- * @param callbackInfo 回调信息
- */
- onReward(placementId, callbackInfo) {
- // ATJSSDK.printLog("AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")");
- this.canGet = true;
- }
- }
- /** 激励视频广告加载状态 */
- export enum RewardAdState {
- /** 未加载 */
- Unload = 0,
- /** 加载中 */
- Loading = 1,
- /** 加载成功 */
- LoadSuccess = 2,
- /** 加载失败 */
- LoadFail = 3,
- /** 播放结束 */
- PlayEnd = 4
- }
|