Ad
Pre-roll image, video, or VAST Linear tag. Requires @nusaplayer/ui. If the creative is HLS, pass hls() in plugins.
import { ad } from '@nusaplayer/plugins'
import hls from '@nusaplayer/hls'
import ui from '@nusaplayer/ui'
Player.make('#player', {
source: { src: 'https://vjs.zencdn.net/v/oceans.mp4' }
})
.use([
ui(),
ad({
vast: 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_ad_samples&sz=640x480&cust_params=sample_ct%3Dlinear&ciu_szs=300x250&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=',
autoplay: true,
plugins: [hls({ qualityControl: false })]
})
])
.create()The tag is fetched in the browser (CORS must allow your site). Wrappers are followed (max 5). MediaFile prefers MP4. Impressions and start / quartile / complete / skip / click tracking pixels are fired.
Still works without VAST:
ad({
autoplay: false,
image: 'https://vjs.zencdn.net/v/oceans.png',
duration: 10,
skipDuration: 5,
target: 'https://example.com'
})UMD: NusaAd({ ... }). Helpers: loadVast(url), parseVast(xml) from @nusaplayer/plugins.
Events: adstart, adend, adskip, aderror.
Options
| Option | Type | Notes |
|---|---|---|
vast | string | VAST tag URL. Fills video, duration, skip, and click-through when those options are omitted |
duration | number | Total ad length in seconds (from VAST <Duration> if omitted) |
skipDuration | number | Seconds before Skip (from Linear skipoffset if omitted) |
image | string | Poster / banner creative |
video | string | Video creative URL (overrides VAST media) |
autoplay | boolean | If false, the user must click to start the ad |
target | string | Click-through URL |
plugins | PlayerPlugin[] | Loaders for the ad video |
position | { top, right, bottom, left } | Skip control placement |
onSkip | (duration: number) => void | Fired when the user skips |