Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Forums

/

playerReady not triggered

2 replies [Last post]

Hi,

I'm trying to track some events as Play and Stop of the player. From http://developer.longtailvideo.com/trac/wiki/FlashApi address I read that:

"Please note that the player will NOT be available the instant your HML page is loaded and the first javascript is executed. The SWF file (40k) has to be loaded and instantiated first! You can catch this issue by defining a simple global javascript function. It is called playerReady(obj) and every player that's succesfully instantiated will call it"

So I checked if the player is called and I see that the player is loaded , usign HTTPwatch i see:

http://www.trespot.it/webanalytics/plugins/content/avreloaded/mediaplayer.swf

This should means that the player is loaded (i don't know if also inizialized). But the playerReady function is never called; here the HTML with playerReady function:

<!-- START OF Video Tracking -->
<!-- Created: 11/15/2009 By GM -->
<!-- START OF Player Track routine -->
<!-- @author maranog -->
<script type="text/javascript">
var player = null;
var playlist = null;
var currentState = null;

function playerReady(obj)
{
alert('the videoplayer '+obj['id']+' has been instantiated');
player = gid(obj.id);
addListeners();
};

function addListeners()
{
playlist = player.getPlaylist();

if((playlist !== null) && (playlist.length > 0))
{
player.addModelListener('STATE', 'stateMonitor');
}
else
{
setTimeout("addListeners();", 100);
}
};

function stateMonitor(obj)
{
currentState = obj.newstate;
previousState = obj.oldstate;

//...do something here based upon the state of the player
//multitrack.Send("DCS.dcssip","www.trespot.it/webanalytics","DCS.dcsuri","/video_events/"+playitem,"WT.clip_n",mediaName,"WT.clip_ev","Play");
//multitrack.Send("DCS.dcssip","www.trespot.it/webanalytics","DCS.dcsuri","/video_events/"+stop,"WT.clip_n",mediaName,"WT.clip_ev","Complete");

if (currentState == "PLAYING") {
dcsMultiTrack("DCS.dcssip","www.trespot.it/webanalytics","DCS.dcsuri","/video_events/"+playitem,"WT.clip_n",mediaName,"WT.clip_ev","Play");
}

if (currentState == "COMPLETED") {
dcsMultiTrack("DCS.dcssip","www.trespot.it/webanalytics","DCS.dcsuri","/video_events/"+stop,"WT.clip_n",mediaName,"WT.clip_ev","Complete");
}

//...only for testing
alert('State: ' + obj.newstate);
};

function gid(name)
{
return document.getElementById(name);
};
</script>

Would you be able to help me?

Thanks.

 
In your player embedding code, you have to define the player id three places:

1) the id attribute of the object element,

2) the name id of the object element,

3) the id flashvar.

Using the embed element for instantiating the player will not enable the JavaScript API. You have to use the double-object method or swfobject to embed the player.

Thanks,

i solved updating the player at the last version (downloaded by this web site) so the function playerReady is correctly called. After this i have added the following code directly in the template HTML (in joomla):

<!-- START OF Video Tracking -->
<!-- Created: 11/15/2009 By GM -->
<!-- START OF Player Track routine -->
<!-- @author maranog -->
<script type="text/javascript">
var player = null;
var playlist = null;
var currentState = null;

function playerReady(obj)
{
alert('the videoplayer ' +obj['id']+ ' è stato inizializzato');
player = gid(obj.id);
addListeners();
};

function addListeners()
{
playlist = player.getPlaylist();

if((playlist !== null) && (playlist.length > 0))
{
player.addModelListener('STATE', 'stateMonitor');
}
else
{
setTimeout("addListeners();", 100);
}
};

function stateMonitor(obj)
{
currentState = obj.newstate;
previousState = obj.oldstate;
var multitrack=new dcsMultiTrack();

//...do something here based upon the state of the player

if (currentState == "PLAYING") {
// multitrack.Send("WT.clip_n", "Tecnologo per caso", "WT.clip_ev", "Play", "WT.dl", "7");
alert('Webtrends: ' + currentState);
}

if (currentState == "BUFFERING") {
// multitrack.Send("WT.clip_n", "Tecnologo per caso", "WT.clip_ev", "Buffering", "WT.dl", "7");
alert('Webtrends: ' + currentState);
}

if (currentState == "COMPLETED"){
// multitrack.Send("WT.clip_n", "Tecnologo per caso", "WT.clip_ev", "Completed", "WT.dl", "7");
alert('Webtrends: ' + currentState );
}

if (currentState == "IDLE") {
// multitrack.Send("WT.clip_n", "Tecnologo per caso", "WT.clip_ev", "Idle", "WT.dl", "7");
alert('Webtrends: ' + currentState );
}

if (currentState == "PAUSED") {
//multitrack.Send("WT.clip_n", "Tecnologo per caso", "WT.clip_ev", "Paused", "WT.dl", "7");
alert('Webtrends: ' + currentState );
}

//...only for testing
alert('State: ' + obj.newstate);
};

function gid(name)
{
return document.getElementById(name);
};
</script>

<!-- END -->