使用小程序奖励视频广告
文档:

注意小程序视频激励广告开发:页面上只能创建一个广告对象
以下是封装方法

export default function(adUnitId) { this.videoAd = false; if(wx.createRewardedVideoAd){ this.videoAd=wx.createRewardedVideoAd({ adUnitId:adUnitId }) } /** * @param opt */ this.show = function(opt){ var defaul_opt = { show_suc:function(){ console.log('video ad show suc'); }, show_fail:function(){}, play_suc:function(){}, play_fail:function(){} } opt = { ...defaul_opt,...opt }; //on error this.videoAd.offError(); this.videoAd.onError(function(err){ console.log('video ad on error',err); }); //load show var that = this; this.videoAd.show().then(opt.show_suc).catch(function(err){ that.videoAd.load().then(function(){ that.videoAd.show().then(opt.show_suc); }).catch(opt.show_fail); }); //on close this.videoAd.offClose(); this.videoAd.onClose((status)=>{ if(status && status.isEnded || status === undefined){ //正常播放结束,可以下发游戏奖励 opt.play_suc(); }else{ //播放中途退出,不下发游戏奖励 opt.play_fail(); } }) } }
然后我们可以直接调用
that.videoAdObj = new adVideoUtil('adunit-fd6c6f6f5129493f');
//playCoinSuc 播放成功执行的方法 //playError 展示视频失败执行的方法 //play_fail 视频播放中途退出执行的方法 this.videoAdObj.show({ play_suc:this.playCoinSuc, show_fail:this.playError, play_fail:this.play_fail })