NusaPlayer

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

OptionTypeNotes
vaststringVAST tag URL. Fills video, duration, skip, and click-through when those options are omitted
durationnumberTotal ad length in seconds (from VAST <Duration> if omitted)
skipDurationnumberSeconds before Skip (from Linear skipoffset if omitted)
imagestringPoster / banner creative
videostringVideo creative URL (overrides VAST media)
autoplaybooleanIf false, the user must click to start the ad
targetstringClick-through URL
pluginsPlayerPlugin[]Loaders for the ad video
position{ top, right, bottom, left }Skip control placement
onSkip(duration: number) => voidFired when the user skips