• 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] || '视频加载错误,重新加载页面试试吧'
    },
  • 相关阅读:
    JS模块化规范CMD之SeaJS
    JavaScript中判断变量类型最简洁的实现方法以及自动类型转换(#################################)
    Flex 弹性布局(****************************************************)
    使用jqMobi开发app基础:弹出内容的设计
    UVA 12232
    MVC5 Entity Framework学习之Entity Framework高级功能
    员工对什么不惬意
    有关Oracle cvu和cvuqdisk
    从Android Handler内部类到WeakReference的知识关联
    把Storyboard减轻的方法
  • 原文地址:https://www.cnblogs.com/caiCheryl/p/11662637.html
Copyright © 2020-2023  润新知