const GameModule = require("../utils/GameModule"); const SkillApi = require('../net/SkillApi'); class ADVideo { //// 有个时候输入的不是对象。。。可能是字符串或者数字 这里做一个兼容 static toNormal(coinCount) { /// 不是正常的金币对象 let newCoin = coinCount; if (coinCount.n == undefined) { newCoin = TapTapTool.goldStrToClass(coinCount + ''); /// 说明是数字 if (newCoin.n == undefined) { newCoin = {'n': newCoin, 'e': 0}; } } return {'e': newCoin.e, 'n': Number(newCoin.n)}; } static wxPlayADVideo(adId,error,close) { let videoAd = wx.createRewardedVideoAd({ adUnitId: adId }) videoAd.load() .then(() => { if (GameModule.audioMng) { GameModule.audioMng.stopBgm(); } videoAd.show() }) .catch(err => { if ((err.errMsg && err.errMsg.includes('fetch advertisement failed')) || (err.errCode && err.errCode == 1004)) { Global.commonAlert.showCommonErrorAlert('今日份视频已经播放完啦~~'); } else { GameGlobal.commonAlert.showCommonErrorAlert('获取视频失败'); } error && error(); }); //处理获取视频错误 videoAd.onError( (res) => { if (res.errMsg) { if (res.errMsg.includes('fetch advertisement failed') || res.errCode == 1004) { Global.commonAlert.showCommonErrorAlert('今日份视频已经播放完啦~~'); } else { GameGlobal.commonAlert.showCommonErrorAlert('获取视频失败'); } } else { GameGlobal.commonAlert.showCommonErrorAlert('获取视频失败'); } error && error(); }); //判断是否完整播放视频 videoAd.onClose((res) => { if (res && res.isEnded || res === undefined) { close && close(true); SkillApi.report(1, (responseData) => { },(error) => { }); } else { close && close(false); } if (GameModule.audioMng) { GameModule.audioMng.playBgm(); } }) } static qqPlayADVideo(error,close) { var isFinished = false; var videoAd = BK.Advertisement.createVideoAd(); videoAd.onLoad(() => { //加载成功 BK.Script.log(1,1,"onLoad") }); videoAd.onPlayStart(() => { if (GameModule.audioMng) { GameModule.audioMng.stopBgm(); } //开始播放 BK.Script.log(1,1,"onPlayStart") }); videoAd.onPlayFinish(() => { //播放结束 BK.Script.log(1,1,"onPlayFinish") isFinished = true; }); videoAd.onError((err) => { //加载失败 BK.Script.log(1,1,"onError code:"+err.code+" msg:"+err.msg); GameGlobal.commonAlert.showCommonErrorAlert('获取视频失败'); error && error(); }); videoAd.onClose(() => { if (isFinished) { //看完完整广告,可下发奖励 close && close(true); SkillApi.report(1, (responseData) => { },(error) => { }); } else { // 未看完广告,不下发游戏奖励 close && close(false); } if (GameModule.audioMng) { GameModule.audioMng.playBgm(); } }); videoAd.show(); } } module.exports = ADVideo;