微信小程序 接入激励式视频广告组件

作者&投稿:安祁 (若有异议请与网页底部的电邮联系)
<button size="mini"  bindtap="openVideoAd" 去完成 </button>

onLoad: function(t) {

    this.videoNum();

},

openVideoAd() {

      wx.showLoading({

        title: '视频正在加载中...',

      });

      if (videoAd) {

        videoAd.show().then(() =>{

          wx.hideLoading()

        }).catch(() => {

          // 失败重试

          videoAd.load().then(() => videoAd.show()).catch(err => {

            console.log('激励视频 广告显示失败')

          })

        })

      }

    },

videoNum: function() {

if (wx.createRewardedVideoAd) {

            videoAd = wx.createRewardedVideoAd({

              adUnitId: t.data.fjl_ad

            })

            videoAd.onLoad((res) => {

            })

            videoAd.onError((err) => {

            })

            videoAd.onClose((status) => {

              console.log(status)

              if (status && status.isEnded || status === undefined) {

                //正常播放结束,可以下发奖励

              } else {

                //不下发奖励

                wx.showModal({

                  content: '广告未播放完成,无法获取次数',

                  showCancel: false

                })

              }

            })

          }

    },

~