Auto Refresh VAST Ads on OPenPLayerJs

To auto-refresh VAST ads on OpenPlayerJs, you can utilize the player’s built-in ad management features. One approach is to use the reset method provided by OpenPlayerJs to reset the VAST ad after a certain interval. This can be achieved by setting a timer to call the reset method periodically.

Here’s an example code snippet in JavaScript:

player.on('adEnd', function() {
setTimeout(function() {
player.vastReset();
}, 30000); // 30 seconds
});

This code listens for the adEnd event, which is triggered when the current ad finishes playing. Once the ad ends, it sets a timer to call the vastReset method after 30 seconds, effectively refreshing the ad.

Another approach is to use the playVast method to play a new VAST ad after a certain interval. This can be achieved by setting a timer to call the playVast method periodically.

Here’s an example code snippet in JavaScript:

setInterval(function() {
  player.playVast({
    tagURL: "path-to-vast-tag.xml",
    id: 'vast_1'
  });
}, 30000); // 30 seconds

This code sets a timer to call the playVast method every 30 seconds, playing a new VAST ad each time.

You can also use the vastAds method to play multiple VAST ads in a playlist, and then use the reset method to refresh the ad playlist.

Here’s an example code snippet in JavaScript:

player.vastAds([
  { tagURL: "preroll-1-ad-tag-url", id: 'vast_1' },
  { tagURL: "midroll-1-ad-tag-url", id: 'vast_2', timeOffset: "00:15" },
  { tagURL: "midroll-2-ad-tag-url", id: 'vast_3', timeOffset: '00:45' }
]);

setInterval(function() {
  player.vastReset();
}, 30000); // 30 seconds

This code sets up a VAST ad playlist with multiple ads, and then sets a timer to call the vastReset method every 30 seconds, refreshing the ad playlist.

Note that you can customize the ad refresh interval and behavior to suit your specific use case.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top