123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- 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;
|