Jelajahi Sumber

看视频间隔功能优化

薛鸿潇 5 tahun lalu
induk
melakukan
b4b6f41677
1 mengubah file dengan 14 tambahan dan 13 penghapusan
  1. 14 13
      assets/script/mk/system/AdSystem.ts

+ 14 - 13
assets/script/mk/system/AdSystem.ts

@@ -35,6 +35,7 @@ export default class AdSystem {
      * @param callBack 广告相关的回调
      * @param callBack 广告相关的回调
      */
      */
     public watchAd(callBack: Function) {
     public watchAd(callBack: Function) {
+        if (this.isAdCooling()) return;
 
 
         this.videoAdcallBack = callBack;
         this.videoAdcallBack = callBack;
 
 
@@ -75,8 +76,8 @@ export default class AdSystem {
      */
      */
     public wacthAdSuccess(placementId = '') {
     public wacthAdSuccess(placementId = '') {
         mk.console.log("wacthAdSuccess");
         mk.console.log("wacthAdSuccess");
-        // if (this.isAdCooling()) return;
         this.videoAdcallBack(true);
         this.videoAdcallBack(true);
+        this.initLastTimeStamp();
     }
     }
 
 
     /** 显示原生广告 */
     /** 显示原生广告 */
@@ -111,26 +112,26 @@ export default class AdSystem {
         }
         }
     }
     }
 
 
-    /** 时评冷却倒计时 */
-    private _ad_cooling_time: number = 0;
+    /** 上次播放视频时间戳,单位:毫秒 */
+    private last_time_stamp: number = 0;
+    private initLastTimeStamp() {
+        let new_date = new Date();
+        this.last_time_stamp = new_date.getTime();
+    }
 
 
     /**
     /**
      * 视频是否冷却
      * 视频是否冷却
      * @returns 视频冷却中
      * @returns 视频冷却中
      */
      */
     private isAdCooling(): boolean {
     private isAdCooling(): boolean {
-        if (this._ad_cooling_time > 0) {
-            mk.tip.pop('当前看视频太频繁了,请' + this._ad_cooling_time + '秒后再试');
+        let new_date = new Date();
+        let new_time_stamp = new_date.getTime();
+        let gap_time_stamp = new_time_stamp - this.last_time_stamp;
+        if (gap_time_stamp <= 5000) {
+            const time = 6 - Math.ceil(gap_time_stamp / 1000);
+            mk.tip.pop('当前看视频太频繁了,请' + time + '秒后再试');
             return true;
             return true;
         }
         }
-        this._ad_cooling_time = 5;
-        this.runCooling();
         return false;
         return false;
     }
     }
-    private runCooling() {
-        this._ad_cooling_time--;
-        if (this._ad_cooling_time > 0) {
-            setTimeout(this.runCooling.bind(this), 1000);
-        }
-    }
 }
 }