Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

scheduling ads via javascript


Hi Team,

I'm adding ad tags via javascript but this below scripting doesn't work, please can you look at it.

var adSchedule="{";
function pushAd(adTime,adTag){
ctrl=true;
if(adTime=="pre" || adTime=="post"){
adStr='roll'+adRollCount+':{offset:"'+adTime+'",tag:"'+adTag+'"},';
}else{
adStr='roll'+adRollCount+':{offset:'+adTime+',tag:"'+adTag+'"},';
}
adSchedule = adSchedule.concat(adStr);
adRollCount++;
}
function commitAds(){
adSchedule = adSchedule.concat("}");
adSchedule = adSchedule.replace("},}", "}}");
}

//Below I'm passing generated 'adSchedule' string to the schedule tag
advertising: {
client: adtype,
'skipoffset':5,
schedule: adSchedule
},

6 Community Answers

pravin.chavan

Best Answer 

Its a script issue, no its not a player version issue.

changing from

var adArr=[];

to

var adArr={};

solved the problem

View in conversation

Ethan Feldman

JW Player Support Agent  
0 rated :

Where is this running?

pravin.chavan

User  
0 rated :

A simple mp4 file, which is roughly 1 hour long, advertising team, wants there ads on pre, post and mid roll. they want it after 10 minutes, 15 minutes, 40 minutes.

So i thought, we might automate this thing, let the php guys when building jw-player, just call a javascript function to add ads, whenever they want.

But unfortunately this doesn't work, so I thought Ethan, Andrew, or anyone of your guys can help us out.

pravin.chavan

User  
0 rated :

Ok,

I've changed pushAd function

var adArr=[];
function pushAd(adTime,adTag){
var subAd={};
subAd.offset=adTime;
subAd.tag=adTag;
adArr['adbreak'+adRollCount]=subAd;
adRollCount++;
}

//then i pass till to below tag
advertising: {
client: adtype,
'skipoffset':5,
schedule: adArr
},

//I add ads from html like this pushAd(offset,adtag);

//Please check below example
http://stg-player.in.com/player/09/

//Also see below file
http://stg-player.in.com/player/09/playercode.js

Ethan Feldman

JW Player Support Agent  
0 rated :

Can you update to 6.9?

https://account.jwplayer.com/#/account

pravin.chavan

Best Answer  User  
0 rated :

Its a script issue, no its not a player version issue.

changing from

var adArr=[];

to

var adArr={};

solved the problem

Ethan Feldman

JW Player Support Agent  
0 rated :

Ah, glad you got it.

This question has received the maximum number of answers.