If you are not an expert in writing code, this Master Class will show you the code you need to add different ad zones using VAST, so you can easily add it to your website to monetize your video content through Fluid Player.

The In-Video (VAST) format allows publishers to have one or multiple ads displayed along a video’s timeline within Fluid Player.

Here is a full list of the JavaScript code parameters:

  • adList: This will allow you to set up one or multiple VastTags. (Please note the VAST tag XML response Content-Type must be either application/xml or text/xml).
  • roll (mandatory): This is used to set the timeline position of Pre-Roll, Mid-Roll, OnPause, Post-Roll.
  • vastTag (mandatory): Ensure that you set it with the url of the VAST XML (Please find the supported tags/attributes here vastLinear.xml).
  • timer (only for mid-roll): This schedules when the ad(s) play either after the specified number of seconds or after a certain percentage of the video content has been viewed.
  • nonLinearDuration (only for nonLinear, optional): The number of seconds until the nonLinear Ad will be shown. If this is not set, the in-video ad will be displayed until the user clicks close [x] or the ad will be displayed until the video ends.\

Resources

The following code is where the Fluid Player resources are placed:

  1. First, add this code within the <head> tag:
  2. <!– Style –>
  3. <link rel=“stylesheet” href=“https://cdn.fluidplayer.com/v2/current/fluidplayer.min.css" (opens in a new tab) type=“text/css”/>
  4. <!– Main Fluid Player Core code –>
  5. <script src=“https://cdn.fluidplayer.com/v2/current/fluidplayer.min.js" (opens in a new tab)></script>
  6. <!– Style –>
  7. <link rel=“stylesheet” href=“https://cdn.fluidplayer.com/v2/current/fluidplayer.min.css" (opens in a new tab) type=“text/css”/>
  8. <!– Main Fluid Player Core code –>
  9. <script src=“https://cdn.fluidplayer.com/v2/current/fluidplayer.min.js" (opens in a new tab)></script>
  10. Then add this code within the <body> tag
  11. //Video content
  12. <video id=“video-ad-list” controls>
  13. <source src=“https://cdn.fluidplayer.com/videos/valerian-720p.mkv" (opens in a new tab) title=“720p” type=“video/mp4”>
  14. </video>

Ad Format code

Each of the codes below define the different options you have to add video ads into the player. This code should be added after the </video> tag.

Pre-Roll

This is the video ad list including the pre-Roll VAST file.

  1. <script type=“text/javascript”>
  2. var testVideo = fluidPlayer(
  3. ‘video-ad-list’,
  4. {
  5. vastOptions: {
  6. “adList” : [{
  7. “valign” : “bottom”, //only for In-Video
  8. “roll” : “preRoll”,
  9. “vastTag” : “https://adservingdomain.com/splash.php?idzone=0000000" (opens in a new tab)
  10. }]
  11. }
  12. }
  13. );
  14. </script>

Mid-Roll

This is the video ad list that includes the Mid-Roll custom options. You can have multiple Mid-Rolls however, only one Pre-Roll and one Post-Roll can be set. Below are two pieces of code, the only difference between them is the way the timer parameter is selected. You can choose the number of seconds “timer” : “8” which will show the ad 8 seconds into the video or you can choose the percentage of video that is show before the ad is shown “timer” : “25%”

  1. <script type=“text/javascript”>
  2. var testVideo = fluidPlayer(
  3. ‘video-ad-list’,
  4. {
  5. vastOptions: {
  6. “adList” : [{
  7. “valign” : “top”, //only for In-Video
  8. “roll” : “midRoll”,
  9. “timer” : “8”,
  10. “nonlinearDuration” : “5”, //only for In-Video
  11. “vastTag” : “https://adservingdomain.com/splash.php?idzone=0000000" (opens in a new tab)
  12. },
  13. {
  14. “valign” : “middle”, //only for In-Video
  15. “roll” : “midRoll”,
  16. “timer” : “25%”,
  17. “nonlinearDuration” : “5”, //only for In-Video
  18. “vastTag” : “https://adservingdomain.com/splash.php?idzone=0000000" (opens in a new tab)
  19. },
  20. {
  21. “roll” : “midRoll”, // In-stream ad
  22. “timer” : “75%”,
  23. “vastTag” : “https://adservingdomain.com/splash.php?idzone=0000000" (opens in a new tab)
  24. }]
  25. }
  26. }
  27. );
  28. </script>

On-Pause

This is the video ad list that includes the On-Pause option.

  1. <script type=“text/javascript”>
  2. var testVideo = fluidPlayer(
  3. ‘video-ad-list’,
  4. {
  5. vastOptions: {
  6. “adList” : [{
  7. “valign” : “bottom”,
  8. “roll” : “onPauseRoll”,
  9. “vastTag” : “https://adservingdomain.com/splash.php?idzone=0000000" (opens in a new tab)
  10. }]
  11. }
  12. }
  13. );
  14. </script>

Post-Roll

This is the video ad list that includes the Post-Roll option.

  1. <script type=“text/javascript”>
  2. var testVideo = fluidPlayer(
  3. ‘video-ad-list’,
  4. {
  5. vastOptions: {
  6. “adList” : [{
  7. “valign” : “top”, //only for In-Video
  8. “roll” : “postRoll”,
  9. “vastTag” : “https://adservingdomain.com/splash.php?idzone=0000000" (opens in a new tab)
  10. }]
  11. }
  12. }
  13. );
  14. </script>

Using all of the ad formats together

Here is the full list of all the video ad options above grouped as one piece of code:

  1. <script type=“text/javascript”>
  2. var testVideo = fluidPlayer(
  3. ‘video-ad-list’,
  4. {
  5. vastOptions: {
  6. “adList” : [
  7. //preRoll
  8. {
  9. “vAlign” : “bottom”, //only for In-Video
  10. “roll” : “preRoll”,
  11. “vastTag” :“https://adservingdomain.com/splash.php?idzone=0000000" (opens in a new tab)
  12. },
  13. //midRoll
  14. {
  15. “valign” : “top”, //only for In-Video
  16. “roll” : “midRoll”,
  17. “timer” : “8”,
  18. “nonlinearDuration” : “5”, //only for In-Video
  19. “vastTag” : “https://adservingdomain.com/splash.php?idzone=0000000" (opens in a new tab)
  20. },
  21. {
  22. “roll” : “midRoll”, // In-sream ad
  23. “timer” : “75%”,
  24. “vastTag” : “https://adservingdomain.com/splash.php?idzone=0000000" (opens in a new tab)
  25. },
  26. //onPauseRoll
  27. {
  28. “valign” : “bottom”, //only for In-Video
  29. “roll” : “onPauseRoll”,
  30. “vastTag” : “https://adservingdomain.com/splash.php?idzone=0000000" (opens in a new tab)
  31. },
  32. //postRoll
  33. {
  34. “valign” : “top”, //only for In-Video
  35. “roll” : “postRoll”,
  36. “vastTag” : “https://adservingdomain.com/splash.php?idzone=0000000" (opens in a new tab)
  37. }
  38. ]
  39. }
  40. }
  41. );
  42. </script>

In this final example this is how the complete code should look for the insertion of one Pre-Roll ad:

  1. <html>
  2. <head>
  3. <!– Style –>
  4. <link rel=“stylesheet” href=“https://cdn.fluidplayer.com/v2/current/fluidplayer.min.css" (opens in a new tab) type=“text/css”/>
  5. <!– Main Fluid Player Core code –>
  6. <script src=“https://cdn.fluidplayer.com/v2/current/fluidplayer.min.js" (opens in a new tab)></script>
  7. </head>
  8. <body>
  9. <!– Video content –>
  10. <video id=“video-ad-list” controls>
  11. <source src=“https://cdn.fluidplayer.com/videos/valerian-720p.mkv" (opens in a new tab) title=“720p” type=“video/mp4”>
  12. </video>
  13. <script type=“text/javascript”>
  14. var testVideo = fluidPlayer(
  15. ‘video-ad-list’,
  16. {
  17. vastOptions: {
  18. “adList” : [
  19. //preRoll
  20. {
  21. “vAlign” : “bottom”, //only for In-Video
  22. “roll” : “preRoll”,
  23. “vastTag” :“https://adservingdomain.com/splash.php?idzone=2947418" (opens in a new tab)
  24. }
  25. ]
  26. }
  27. }
  28. );
  29. </script>
  30. </body>
  31. </html>

For more information please visit Fluid Player’s documentation page (opens in a new tab).

Fluid Player Community

Fluid Player is open source, so join the community and see what new features developers are creating for Fluid Player on GitHub (opens in a new tab).