wx小程序 createRewardedVideoAd

 

onLoad  加载模块
  this.videoAdCreat()
onUnload  销毁模块
  this.videoAd.destroy()

***********************************************
注意点:
  
  01 视频加载失败 1004 无合适广告

  02 非法退出 物理返回

    a. cant invoke show() while other video-ad is showed

    b.操作:观看完毕-非法退出-再进页面-再次退出-再次近页面
     导致:直接走了观看成功方法

    解决:进行销毁 RewardedVideoAd.destroy()

***********************************************
videoAdCreat(){
// 在页面onLoad回调事件中创建激励视频广告实例
if (wx.createRewardedVideoAd) {
this.videoAd = wx.createRewardedVideoAd({
adUnitId: 'adunit-fec0f7dc798dd96b'
})
this.videoAd.onError((err) => {
wx.showToast({
title: this.videoAdErrHandle(err),
icon: 'none'
})
})
// 监听关闭
this.videoAd.onClose((status) => {
if (status && status.isEnded || status === undefined) {
const id = this.backEndVideoInfo.item.id
console.log('视频正常关闭 下发奖励')
indexModel.videoAddWatched({
id: id
}).then(res => {
console.log('后台修改01')
res.success && this.circulateTaskList.map(ite => {
if (ite.id === id) {
ite.status = 1;
}
})
})
} else {
// 播放中途退出,进行提示
wx.showToast({title: '未完整观看视频不能获取奖励哦', icon: 'none'})
}
})
}
},
videoAdLoad(){
// 用户触发广告后,显示激励视频广告
if (this.videoAd) {
this.videoAd.show().catch((err) => {
this.videoAd.load()
.then(() => this.videoAd.show())
.catch(err => {
wx.showToast({
title: this.videoAdErrHandle(err),
icon: 'none'
})
})
})
}
},
videoAdErrHandle(err){
console.log('视频加载失败')
console.log(err)
// {errMsg: "no advertisement", errCode: 1004}
const errHandle={
1000:'后端接口调用失败',
1001:'参数错误',
1002:'广告单元无效',
1003:'内部错误',
1004:'无合适的广告',
1005:'广告组件审核中',
1006:'广告组件被驳回',
1007:'广告组件被封禁',
1008:'广告单元已关闭',
}
return errHandle[err.errCode] || '视频加载错误,重新加载页面试试吧'
},

 

posted @ 2019-10-12 17:01  丶七月小先生丶  阅读(5143)  评论(0编辑  收藏  举报