change vast ads dynamically with media in kaltura

984 Views Asked by At

I'm trying to change media and corresponding vast ads with button clicks in kaltura. I'm using the kdp.setKDPAttribute("configProxy.flashvars.vast","prerollUrl",$(this).attr('preroll')); to set the vast preroll url for the media. Mediafiles I'm using are of url type. I'm adding the setkdpaddtibute in kWidget.addReadyCallback(function(videoId) where I do the kdp.sendNotification( "changeMedia", { 'entryId' : $(this).attr('data-entryId') });

  <script type="text/javascript">
    kWidget.addReadyCallback(function(videoId){
        // add a local ref to the kdp: 
        var kdp = document.getElementById( videoId );
        $( '.changeMedia' ).click(function(){
            kdp.setKDPAttribute("configProxy.flashvars.vast","prerollUrl",$(this).attr('preroll'));
            kdp.sendNotification( "changeMedia", { 'entryId' : $(this).attr('data-entryId') });
            });
        // change media run at the start of the changeMedia sequence
        kdp.kBind('changeMedia', function(data){
            if( data.entryId ){

            $("#changeLog").append( "EntryId: " + data.entryId + "\n");
            }
            })
        // entry ready is run once the entry data has been loaded
        kdp.kBind('entryReady', function(){
            $("#changeLog").append( " Name: " + kdp.evaluate('{mediaProxy.entry.name}') + "\n" );
            })
    });

I use the following for the button

I specify the following vast parameters along with the player

<script>
  kWidget.embed( 'kaltura_player', {
          'wid' : '_1748561',
          'uiconf_id': '24326282',
          'flashvars': {
              'sourceType':'url',
              'autoPlay': 'true',
              "adsOnReplay" : true,
              "vast": {
              "numPreroll" : "1",
              "skipBtn" : "skip",
              "skipOffset" : "5",
              "prerollStartWith" : "",
              "preSequence" : "1",
              "prerollUrl":"",
              "storeSession" : false,
              "unescapeAdUrls" : false,
              "timeout":"10"
              }
            }
          });
</script>

when I load the page, the vast ads donot play. Only the video file plays. Also, kaltura player is sending a http://myserver.com/serverip request to my server. What response does the player expect from the server? thanks phani

2

There are 2 best solutions below

1
On

The vast plugin doesnt support dynamic switching of the url. my suggestion will be to re-embed the player anytime you want to change the url. kWidget.destroy(..) and then kWidget.embed({..new preroll url..})

0
On

You can do it without re-embedding the player, just reload the media. Here's how:

    var entryId = kdp.evaluate('{mediaProxy.entry.id}');
    var prerollUrl = 'your smashingly fancy new url';
    kdp.sendNotification('cleanMedia');
    kdp.setKDPAttribute("vast", "preSequence", 1);
    kdp.setKDPAttribute("vast", "prerollUrl", prerollUrl);
    kdp.sendNotification('changeMedia', {
      'entryId': entryId
    });