Prebid Video | Instream Example with Flowplayer

An example of an instream pre-roll ad using Prebid.js and Flowplayer.


Important: This example uses a test version of Prebid.js hosted on our CDN that is not recommended for production use. It includes all available adapters. Production implementations should build from source or customize the build using the Download page to make sure only the necessary bidder adapters are included.

The button will be enabled only during ads

Warning: Do not forget to exchange the placementId in the code examples with your own placementId!

Place this code in the page header.

<script async src="//"></script>
<link rel="stylesheet" href="//">
<script src="//"></script>
<script src="//"></script>
<script src="//"></script>
    #player {
        max-width: 40em;
        width: 100%;
        float: left;

    #controls {
        float: left;
        padding: 1em;
  var pbjs = pbjs || {};
  pbjs.que = pbjs.que || [];

  // The ad tag in Flowplayer can be actual ad tag or promise to an ad tag.  
  // We return the ad tag if it is available before the player is ready to play  
  // Otherwise the player waits for 2 secs for tag to be available.
var adtag = null var timeout = 2000 var asyncTag = function() { if (adtag) return Promise.resolve(adtag) return new Promise(function (resolve) { setTimeout(function() { resolve(adtag) }, timeout) }) } /* Prebid Video adUnit */ var videoAdUnit = { code: 'video1', sizes: [640,480], mediaTypes: { video: { context: "instream" } }, bids: [ { bidder: 'appnexus', params: { placementId: '13232361', // Add your own placement id here
video: { skipppable: true, playback_method: ['auto_play_sound_off'] } } } ] }; pbjs.que.push(function(){ pbjs.addAdUnits(videoAdUnit); // add your ad units to the bid request
pbjs.setConfig({ debug: true, cache: { url: '' } }); pbjs.requestBids({ bidsBackHandler: function(bids) { var videoUrl = pbjs.adServers.dfp.buildVideoUrl({ adUnit: videoAdUnit, params: { iu: '/19968336/prebid_cache_video_adunit', cust_params: { section: "blog", anotherKey: "anotherValue" }, output: "vast" } }); adtag = videoUrl; } }); }); </script>

Place this code in the page body.

<div id="player"></div>
<!--video player div-->
<div id="player"></div>
<div id="controls">
    <button id="ad-toggle" disabled>
        Toggle ad playback
    <p>The button will be enabled only during ads</p>
<script type="text/javascript">
  var player = flowplayer('#player', {
    src: "//",
    title: "Flowplayer demo",
    description: "Demo showing ads",
    autoplay: true,
    ima: {
      ads: [
  var btn = document.querySelector('#ad-toggle');

  btn.addEventListener('click', function() {
    if (;

  function toggleDisabled(disabled) {
    return function() { btn.disabled = disabled }
  }, toggleDisabled(false));, toggleDisabled(true));, toggleDisabled(true));