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] || '視頻加載錯誤,重新加載頁面試試吧'
},

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM