美文网首页
小程序激励式视频广告使用

小程序激励式视频广告使用

作者: _conquer_ | 来源:发表于2019-04-22 11:11 被阅读0次

    文档:https://wximg.qq.com/wxp/assets/pdf/reward0415.pdf
    注意:一个页面只能创建一个广告对象
    以下是封装的方法

    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();
                }
            })
        }
        
    }
    

    然后我们直接调用就可以了

    • 首先我们在onload的时候创建一个广告对象
    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
    })
    

    相关文章

      网友评论

          本文标题:小程序激励式视频广告使用

          本文链接:https://www.haomeiwen.com/subject/aonegqtx.html