Ima plugin - reset and request ads

In a previous blog we have described how to reset or set new VAST ads either for video playlist items or for new video loaded programmatically. Now we will describe how to reset or load new Google video ads, also know as Google Ima ads, served through Ima plugin by Google.

It is highly suggested to use Google ads for video through Ima plugin developed by Google. Additionally, we have tweaked Ima plugin to fix some unexpected issues. By default Ima ads container for non-linear ads covers entire player, making player controls inaccessible, including control bar buttons. This was fixed by us and now practically every control is available to use.

Many users asked us how to reset or load another Ima tag for playlist video items or for video loaded programmatically.

In a previous blog we attached an example of function to change video source and reset VAST ads. Here's similar function, but with code to reset and load Google Ima ads.

Code snippet
  function buttonclick() {
   var new_source = {
      sources: [
        {src:"//path-to-video_720p.mp4",type:"video/mp4",res:"720",label:"720p", default:true}, 
        {src:"//path-to-ideo_360p.mp4",type:"video/mp4",res:"480",label:"480p"}, 
        {src:"/path-to-video_240p.mp4",type:"video/mp4",res:"360",label:"360p"}
     ],
     title: 'new video title'
    }
    player.changeSource( new_source);

    player.ima.changeAdTag (Google_Ima_tag);
    player.ima.requestAds();
  }

Requesting Ima ads for playlist video item is exactly the same.

Code snippet
player.on('playlist_change', function(event,data) {
    player.ima.changeAdTag (Google_Ima_tag);
    player.ima.requestAds();
});

You may find useful option not to reset ads on first playlist item play

Code snippet
player.on('playlist_change', function(event,data) {
   if( data.firstPlay!=true ) { 
      player.ima.changeAdTag (Google_Ima_tag);
      player.ima.requestAds();
   }
});

You may also request ads only for certain video item from playlist.

Code snippet
player.on('playlist_change', function(event,data) {
   if( data.id == 3) { 
      player.ima.changeAdTag (Google_Ima_tag);
      player.ima.requestAds();
   }
});
The function above will request Ima Ads only for 3rd video in the playlist.
Nuevodevel Blog
Nuevodevel Tweeter