# Rewarded Video Ad
The rewarded video ad component is composed of the client's native image, text, and video controls. It has the highest level and will cover the on-screen canvas.
The developer can call wx.createRewardedVideoAd to create a rewarded video ad component. This method returns a global singleton.
let video1 = wx.createRewardedVideoAd({ adUnitId: 'xxxx' })
let video2 = wx.createRewardedVideoAd({ adUnitId: 'xxxx' })
console.log(video1 === video2)
// true
The rewarded video ad component is hidden by default. Therefore, it can be created and initialized in advance.
let rewardedVideoAd = wx.createRewardedVideoAd({ adUnitId: 'xxxx' })
In order to avoid abusing advertisement resources, currently the number of rewarded video ads every user can watch per day is limited. It is recommended that you should determine whether the ads are pulled successfully before displaying the ads button.
# Show/Hide
The rewarded video ad component is hidden by default. RewardedVideoAd.show() should be called to display the component.
bannerAd.show()
The ad will only be closed when the user clicks the Close Ad
button on the rewarded video ad component. Developers cannot control the hiding of the rewarded video ad component.
# Success and Failure of Advertisement Pulls
The rewarded video ad component automatically pulls the ads and updates them. After the component is created, an ad will be pulled. After the users clicks the Close Ad
button, the next ad will be pulled.
If the pull is successful, RewardedVideoAd.onLoad() is executed, and the Promise returned by RewardedVideoAd.show() will be a resolved Promise. No parameters are passed for both callback functions.
rewardedVideoAd.onLoad(() => {
console.log('Rewarded video ad loaded successfully')
})
rewardedVideoAd.show()
.then(() => console.log('Rewarded video ad display'))
If the pull fails, the callback function registered via RewardedVideoAd.onError() will be executed and the parameter of the callback function is an object containing the error message. Common unusual errors reference documentation
rewardedVideoAd.onError(err => {
console.log(err)
})
RewardedVideoAd.show() The returned Promise will also be a resolved Promise.
rewardedVideoAd.show()
.catch(err => console.log(err))
# Pull failed, pull again
If one of the component's automatic pulls fails, the subsequent show() calls will be rejected. You can call RewardedVideoAd.load() to manually re-pull the ad.
rewardedVideoAd.show()
.catch(err => {
rewardedVideoAd.load()
.then(() => rewardedVideoAd.show())
})
If a component’s automatic pull is successful, then calling the load() method will return a resolved Promise directly without pulling the ad.
rewardedVideoAd.load()
.then(() => rewardedVideoAd.show())
# Listen Users Closing Advertisements
The ad will only be closed when the user clicks the Close Ad
button on the rewarded video ad component. This event can be listened via RewardedVideoAd.onClose().
In the base library below 2.1.0, the Close Button
is displayed after rewarded video playback ends, so onClose is triggered only after playback ends. When onClose
is triggered, this indicates the user has watched the video.
In the base library 2.1.0 or above, the Close Button
is always displayed, as shown below:
The callback function of RewardedVideoAd.onClose() will pass in a parameter res with res.isEnded
describing the state when the ad was closed.
Property | Type | Description |
---|---|---|
isEnded | boolean | Whether the video is closed when the user completes the viewing. True indicates that the user closes the video after it is done playing. False indicates that the user closes the video during playback |
In the base library 2.1.0 or above, the developer needs to determine whether the video has finished playing and a reward can be issued to the user based on res.isEnded
.
rewardedVideoAd.onClose(res => {
// The user has clicked the **Close Ad** button
// In the base library below 2.1.0, res is undefined.
if (res && res.isEnded || res === undefined) {
// After the normal playback ends, game reward can be issued
}
else {
// The user exited before playback ended, no game reward is issued.
}
})