小程序開放激勵視頻是對小程序開發者一個福音,小程序開發者可以完成一些變現,以增加收入!
本文章針對已經有開發經驗或者正在進行小程序開發的同學~
官方文檔:激勵視頻廣告
1.定義頁面變量,用於創建視頻實例
const = {
videoAd: null
}
2.創建廣告視頻
/**
* @method createVideoAd 創建廣告視頻
*/
createVideoAd() {
// 創建廣告位
if (wx.createRewardedVideoAd) {
// 加載激勵視頻廣告
this.const.videoAd = wx.createRewardedVideoAd({
adUnitId: 'adunit-7526e41971f4e415'
})
//捕捉錯誤
this.const.videoAd.onError(err => {
// 進行適當的提示
wx.showToast({
title: '視頻異常',
icon: 'none'
})
})
// 監聽關閉
this.const.videoAd.onClose((status) => {
if (status && status.isEnded || status === undefined) {
// 正常播放結束,下發獎勵
this.doubleReward()
} else {
// 播放中途退出,進行提示
wx.showToast({
title: '未完整觀看視頻',
icon: 'none'
})
}
})
}
}
3.調用播放視頻播放
/**
* @method loadVideo 加載視頻並播放
*/
loadVideo(){
if(this.const.videoAd){
this.const.videoAd.load()
.then(() => {
this.const.videoAd.show()
})
.catch(err => {
// 視頻加載失敗重試,酌情添加
this.const.videoAd.load()
.then(() => {
this.const.videoAd.show()
})
.catch(err => {
wx.showToast({
title: '視頻加載失敗!',
icon: 'none'
})
})
})
}
}
4.具體使用
...
// 頁面觸發tap事件調用
viewVideo() {
this.loadVideo()
}
...
onLoad() {
this. createVideoAd()
}
5.使用場景
- 商城觀看激勵視頻獲取響應折扣
- 觀看視頻查看更多內容
- 步數類觀看視頻獲取額外加成
以上為wepy小程序中添加激勵視頻的實現方法。大家有什么好的激勵視頻使用場景可在評論區留言,可以分享給大家!