123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- const GameModule = require("../utils/GameModule");
- const SkillApi = require('../net/SkillApi');
- // const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- const {GameNotificationKey, ADVideoLoadState} = require('../utils/GameEnum');
- class ADVideo {
- // constructor() {
- // this.isNeedShowErr = false;
- // }
- wxCreateADVideo() {
- let defualtADdId = 'adunit-9d6b728b8e8a52d3';
- let videoAd = wx.createRewardedVideoAd({
- adUnitId: defualtADdId
- });
- /// 默认是加载成功的 啦
- Global._adVideoState = ADVideoLoadState.success;
- this.videoAd = videoAd;
- videoAd.load()
- .then(() => {
- this.isFirstLoad = false;
- Global._adVideoState = ADVideoLoadState.success;
- GameEvent.fire(GameNotificationKey.AdUpdateStateNotification, ADVideoLoadState.success);
- console.log('视频加载成功');
- })
- .catch(err => {
- // if ((err.errMsg && err.errMsg.includes('fetch advertisement failed')) || (err.errCode && err.errCode == 1004)) {
- // Global.commonAlert.showCommonErrorAlert('今日份视频已经播放完啦~~');
- // } else {
- // Global.commonAlert.showCommonErrorAlert('获取视频失败');
- // }
- this.handelVideoErr(err);
- this.isFirstLoad = false;
- });
- // videoAd.onLoad(() => {
- // /// 视频加载成功
- // Global._adVideoState = ADVideoLoadState.success;
- // GameEvent.fire(GameNotificationKey.AdUpdateStateNotification, ADVideoLoadState.success);
- // console.log('视频加载成功');
- // });
- // 处理获取视频错误
- videoAd.onError( (res) => {
- this.handelVideoErr(res);
- });
-
- videoAd.onClose((res) => {
- if (res && res.isEnded || res === undefined) {
- console.log('视频正常关闭');
- GameEvent.fire(GameNotificationKey.AdUpdateStateNotification, ADVideoLoadState.closeFinish, this.callBackObjct);
- } else {
- console.log('视频未正常关闭');
- GameEvent.fire(GameNotificationKey.AdUpdateStateNotification, ADVideoLoadState.closeFail, this.callBackObjct);
- }
- if (GameModule.audioMng) {
- GameModule.audioMng.playBgm();
- }
- SkillApi.report(1, (responseData) => {
- },(error) => {
- });
- })
- }
- /// 需要在close中回调的对象
- showVideo(callBackObjct = null) {
- this.callBackObjct = callBackObjct;
- this.videoAd.load()
- .then(() => {
- if (GameModule.audioMng) {
- GameModule.audioMng.stopBgm();
- }
- this.videoAd.show();
- })
- .catch(err => {
- // if ((err.errMsg && err.errMsg.includes('fetch advertisement failed')) || (err.errCode && err.errCode == 1004)) {
- // Global.commonAlert.showCommonErrorAlert('今日份视频已经播放完啦~~');
- // } else {
- // Global.commonAlert.showCommonErrorAlert('获取视频失败');
- // }
- if (err.errMsg && err.errMsg.includes('video-ad is showed')) {
- Global.commonAlert.showCommonErrorAlert('视频正在播放请不要重复点击~~');
- return;
- } else {
- this.handelVideoErr(err);
- }
- });
- }
- handelVideoErr(res) {
- // if (isShow) {
- // Global.commonAlert.showCommonErrorAlert('获取视频失败');
- // }
- Global._adVideoState = ADVideoLoadState.fail;
- console.log('获取视频失败 fa' + res.errMsg);
- GameEvent.fire(GameNotificationKey.AdUpdateStateNotification, ADVideoLoadState.fail);
- }
- // static wxPlayADVideo(adId,error,close) {
- // let videoAd = wx.createRewardedVideoAd({
- // adUnitId: adId
- // })
- // //处理获取视频错误
- // videoAd.onError( (res) => {
- // if (res.errMsg) {
- // if (res.errMsg.includes('fetch advertisement failed') || res.errCode == 1004) {
- // Global.commonAlert.showCommonErrorAlert('今日份视频已经播放完啦~~');
- // } else {
- // Global.commonAlert.showCommonErrorAlert('获取视频失败');
- // }
- // } else {
- // Global.commonAlert.showCommonErrorAlert('获取视频失败');
- // }
- // error && error();
- // });
- // //判断是否完整播放视频
- // videoAd.onClose((res) => {
- // if (res && res.isEnded || res === undefined) {
- // close && close(true);
- // } else {
- // close && close(false);
- // }
- // if (GameModule.audioMng) {
- // GameModule.audioMng.playBgm();
- // }
- // SkillApi.report(1, (responseData) => {
- // },(error) => {
- // });
- // })
- // }
- // static buildingAdId = 'adunit-4ac219410677b685'
- // static roomAdId = 'adunit-70b8fbdab9e3e7a8'
- // static offlineAdId = 'adunit-a104eef5cc68d0d3'
- // /// 抽奖广告id
- // static drawAdId = 'adunit-d067ec556ad5c9c2'
- // ///商城广告id
- // static storeAdCoinId = 'adunit-3494836fc16b0e76'
- // static storeAdDiamand = 'adunit-9d6b728b8e8a52d3'
- // static resetAdId = 'adunit-72f6285169164939'
- // static starAdId = 'adunit-0e09f5a550f077ab'
- }
- module.exports = ADVideo;
- // module.exports = ADVideoLoadState;
|