playAd(tag)

🚧

Since playAd(tag) will be deprecated as of JW 8.31.0, use loadAdTag(tag).

Used to play an ad immediately, which is primarily useful for situations where the built-in ad schedule of JW Player cannot be used. (e.g. for live streaming or dynamic ads for playlist items)

AttributeDescription
tag* stringVAST tag URL that should be loaded into the player

We recommend to call playAd() in one of these following situations:

  • Inside a JW Player event handler for beforePlay() to trigger a pre-roll
  • Inside a JW Player event handler for onTime() to trigger a mid-roll
  • Inside an event handler for on('BeforeComplete') to trigger a post-roll
  • Outside of event handlers, only when the player is in the playing state

📘

playAd() is not supported when using Player Bidding due to the potential impact on performance and user experience while the player is waiting for the bidding process to complete.

playAd() is also not supported with ad preloading. Since calling playAd() immediately plays an ad, there is no time to preload an ad.