|
@@ -15,22 +15,32 @@ class ADVideo {
|
|
|
/// 默认是加载成功的 啦
|
|
|
Global._adVideoState = ADVideoLoadState.success;
|
|
|
this.videoAd = videoAd;
|
|
|
- videoAd.onLoad(() => {
|
|
|
- /// 视频加载成功
|
|
|
- Global._adVideoState = ADVideoLoadState.success;
|
|
|
- GameEvent.fire(GameNotificationKey.AdUpdateStateNotification, ADVideoLoadState.success);
|
|
|
- console.log('视频加载成功');
|
|
|
+
|
|
|
+ videoAd.load()
|
|
|
+ .then(() => {
|
|
|
+ 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);
|
|
|
});
|
|
|
|
|
|
+ // videoAd.onLoad(() => {
|
|
|
+ // /// 视频加载成功
|
|
|
+ // Global._adVideoState = ADVideoLoadState.success;
|
|
|
+ // GameEvent.fire(GameNotificationKey.AdUpdateStateNotification, ADVideoLoadState.success);
|
|
|
+ // console.log('视频加载成功');
|
|
|
+ // });
|
|
|
+
|
|
|
//处理获取视频错误
|
|
|
videoAd.onError( (res) => {
|
|
|
- if (this.isNeedShowErr) {
|
|
|
- Global.commonAlert.showCommonErrorAlert('获取视频失败');
|
|
|
- }
|
|
|
- Global._adVideoState = ADVideoLoadState.fail;
|
|
|
- this.isNeedShowErr = true;
|
|
|
- console.log('获取视频失败 fa' + res.errMsg);
|
|
|
- GameEvent.fire(GameNotificationKey.AdUpdateStateNotification, ADVideoLoadState.fail);
|
|
|
+ this.handelVideoErr(res);
|
|
|
});
|
|
|
|
|
|
|
|
@@ -53,12 +63,37 @@ class ADVideo {
|
|
|
}
|
|
|
/// 需要在close中回调的对象
|
|
|
showVideo(callBackObjct = null) {
|
|
|
- if (GameModule.audioMng) {
|
|
|
- GameModule.audioMng.stopBgm();
|
|
|
- }
|
|
|
- console.log('开始播放视频');
|
|
|
this.callBackObjct = callBackObjct;
|
|
|
- this.videoAd.show();
|
|
|
+ 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 (this.isNeedShowErr) {
|
|
|
+ Global.commonAlert.showCommonErrorAlert('获取视频失败');
|
|
|
+ }
|
|
|
+ Global._adVideoState = ADVideoLoadState.fail;
|
|
|
+ this.isNeedShowErr = true;
|
|
|
+ console.log('获取视频失败 fa' + res.errMsg);
|
|
|
+ GameEvent.fire(GameNotificationKey.AdUpdateStateNotification, ADVideoLoadState.fail);
|
|
|
}
|
|
|
|
|
|
// static wxPlayADVideo(adId,error,close) {
|
|
@@ -66,21 +101,7 @@ class ADVideo {
|
|
|
// 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 {
|
|
|
- // Global.commonAlert.showCommonErrorAlert('获取视频失败');
|
|
|
- // }
|
|
|
- // error && error();
|
|
|
- // });
|
|
|
+
|
|
|
|
|
|
// //处理获取视频错误
|
|
|
// videoAd.onError( (res) => {
|