# Post an ad in front of the video

Weixin Mini Program Ad Traffic Master Operating Instructions: Document Address Developers can add property configurations to the video components to create the Weixin Mini Program pre-video ad component, which automatically pulls ad data when created and displays ads before the video plays.

# Advertising style

The presentation style is in the video component set by the developer, at a scale of 16 by 9, vertically or horizontally centered

# Advertising Creation

The following ad-related property configurations were added to the video components to display the corresponding ad after settingad-unit-id

attribute type Default values Required to fill in Introductions
ad-unit-id string yes Advertising unit id, can be in Weixin Mini Program management background traffic main module new
bindadload eventhandle no A callback to successful ad loading
bindaderror eventhandle no AD load failed callback, return code with ad component
bindadclose eventhandle no A correction for ad closure
bindadplay eventhandle no Advertisement start, end playback event.detail = {type: 'begin / end'}

Add an ad unit to bind an ad event

<video 
  class="xxx"
  src="xxx"
  bindadplay="onAdplay"
  bindadload="onAdload"
  bindadclose="onAdclose"
  bindaderror="onAdError"
  ad-unit-id="xxx"
>
</video>

Broadcasting incidents

Page({
  onAdplay(e) {
    console.log('onAdplay', e)
  },
  onAdload(e){
    console.log('onAdload', e)
  },
  onAdclose(e) {
    console.log('onAdclose', e)
  },
  onAdError(e) {
    console.log('onAdError', e)
  },
})

# Ads are preloaded

Developers can preload ads by callingwx.preloadVideoAd


const adUnitId1 = 'xxx'
const adUnitId2 = 'xxx'
wx.preloadVideoAd([adUnitId1, adUnitId2])

# Error code

The error code is an error message obtained through a bindaderror callback, before posting ads and thenordinary ad components ad error code The following error code has been added.

code Exceptions Solutions
3001 Target control strategy According to no advertisements.
3002 Target control strategy According to no advertisements.
3003 Target control strategy According to no advertisements.
3004 Target control strategy According to no advertisements.

# Note

1, support video preloading capabilities: document address .

2, only support the same layer of rendering mode video component.

3, the developer can monitor the bindadplay event to get the advertising playback status, and make corresponding processing.

  1. Ad-unit-id does not support asynchronous settings, only in thedataattribute of a wxml or a js file, and is invalid bysetData.
  1. Do not display ads in front of the video in full screen mode.