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

Check if player is ready to load and play


Hi, i'm just wondering is there any best or recommended solution to check if player is ready or not?

For now, i'm using bc.. setTimeout();
to get a little delay for player, is this a best solution or there is another solution than this?

Thanks...

9 Community Answers

JW Player

User  
0 rated :

Do we need to set timeout both in load and play?
ex: bc.. setTimeout("player.sendEvent('LOAD', {file:'"+file+"', type:'video'})",500);
setTimeout("player.sendEvent('PLAY','true')",100);



Thanks..

JW Player

User  
0 rated :

@Hudoq,

For the v4.x player, the correct way to check if the player is ready is to use the playerReady() function:bc.. function playerReady(obj)
{
...some action here...
};


The player will call this function when it is ready.

Please see the API documentation here: *http://code.longtailvideo.com/trac/wiki/FlashAPI*

JW Player

User  
0 rated :

@kLink,

When already using *playerReady*, is it setTimeout is still necessary to used?

Thanks

JW Player

User  
0 rated :

@Hudoq,

Yes, it seems to be more reliable to use setTimeout():bc.. setTimeout("player.sendEvent('PLAY', 'true')", 100);



JW Player

User  
0 rated :

@kLink,

Oke, thanks.

I try to take some small conclusion with this, i assume that we need to *settimeout* every time we want to send some event to the player. is it right?

This my code: bc.. function playerReady(obj){
var id = obj['id'];
player = document.getElementsByName(id)[0];

if(id == 'mediaplayer'){
setTimeout("player.sendEvent('LOAD', {file:'"+file+"', type:'video'})",500);
setTimeout("player.sendEvent('PLAY','true')",100);
}
};


What do u think about my code?

Thanks...

JW Player

User  
0 rated :

@kLink,

Thanks.. Do you know that i just realize why i cannot setTimeout in *'PLAY'* event? seems that settimeout is not working in 'PLAY' statement, when i try this code: bc.. setTimeout("player.sendEvent('PLAY', 'true')", 5000);
why i'm not getting any delay? is there any way to set like dummy delay before playing the video? cos i also try this: bc.. setTimeout(5000); or setTimeout("",5000);
delay still not working...

-Thanks-

JW Player

User  
0 rated :

Hi',

I found really strange behaviour in setTimeout statement, when i try this : bc.. setTimeout("player.sendEvent('PLAY')", 5000);
it will not delay the 'PLAY' event, but seems it will tell the player only 'PLAY' the video for 5 seconds, is it correct behaviour? or this is some bug?

Thanks...

JW Player

User  
0 rated :

So' maybe there is no explanation for this?

JW Player

User  
0 rated :

Ifiwrotethecode,itwouldlooklikethis:bc.. functionplayerReady(obj)
{
player=document.getElementsByName(obj.id)[0];

setTimeout("player.sendEvent('LOAD',{file:file,type:'video'})",100);
setTimeout("player.sendEvent('PLAY','true')",500);
};



Youdon'tneedmuchofadelaybeforeloadingafile(assumingthatyouhavedefined
theglobalvariable*file*somewhereelse).

Butyoudoneedalongerdelayaftertheloadeventbecauseitmighttakesometime
togettheplaylistandloadit.

ThebestwaywouldbetogetareturnvaluefromsendEvent('LOAD',obj)toconfirm
thatthefilewasloadedsuccessfully.

Idon'tknowifsendEvent()returnsanything,I'llhavetotestit.

Theotherthingthatyoucoulddo,istocheckthestateoftheplayer
afterthesendEvent('LOAD',obj)toseeiftheplayerisready.

Again,Idon'tknowiftheplayerchangesstatewhenafileisloaded,I'llhavetotestthatalso.

This question has received the maximum number of answers.