zoukankan      html  css  js  c++  java
  • 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] || '视频加载错误,重新加载页面试试吧'
    },
  • 相关阅读:
    腾讯开源 APIJSON 连创五个第一
    最火的分布式 HTAP 数据库 TiDB
    完爆Facebook/GraphQL,APIJSON全方位对比解析(三)-表关联查询
    后端自动化版本管理,再也不用改URL了!
    后端开挂:3行代码写出8个接口!
    3步创建服务端新表及配置
    Activity猫的一生-故事解说Activity生命周期
    APIJSON-以坚持和偏执,回敬傲慢和偏见
    APIJSON,让接口和文档见鬼去吧!
    Android 100多个Styles快速开发布局XML,一行搞定View属性,一键统一配置UI...
  • 原文地址:https://www.cnblogs.com/caiCheryl/p/11662637.html
Copyright © 2011-2022 走看看