The following video is played automatically, but only if you visit this page the first time. For testing purposes, there is also a button, which can be used to reset this mechanism. So if you reload this page, the player should only start, if you previously have hit the reset button. Since cut&paste of code does not always work reliably, the code of this example can be downloaded at the bottom of this page.
Adobe Flash Player not installed or older than 9.0.115!
How it works
The media code, used for this player is {flvdivid="onlyonce" enablejs="true"}acera{/flv}. As you can see, the player has been given a specific ID, so that it can be referenced later by that id. Furthermore, scripting has been enabled.
The actual effect is achieved by doing two things:
Inserting the following JavaScript code in the header section of the template html. This code defines a function named startPlayerOnce(), which takes the ID of the player. It checks for a cookie by the name of "pseen_"+id and if this cookie does not yet exist, calls the predefined API function AvrPlay('p_'+id) to start the player.
<script type="text/javascript">
//<[CDATA[function tryStartPlayer(pid){try{new allvideos.API(pid).play();
}catch(e){// Starting the player may fail, if the page is not yet// fully loaded and it does not exist yet.// So we retry it a little bit later.
window.setTimeout('tryStartPlayer("'+pid+'")', 500);
}}function startPlayerOnce(id){// Search for the cookievar nameEQ = 'pseen_'+id+'=';
var ca = document.cookie.split(';');
// Loop over all cookie varsfor(var i = 0; i < ca.length; i++){var c = ca[i];
while(c.charAt(0) == ' '){
c = c.substring(1, c.length);
}if(c.indexOf(nameEQ) == 0){// If we arrive here, We found the// cookie and therefore simply returnreturn;
}}// If we arrive here, cookie wasn't found, so// let's create it and start the player// The new cookie expires after one year.var now = new Date();
now.setTime(now.getTime() + (365 * 24 * 60 * 60 * 1000));
var expires = ' expires='+now.toGMTString()+';';
// If you want the cookie last for only a session lifetime// (next visit, the video plays once again) then uncomment// the following line://expires = '';
document.cookie = nameEQ + '1;'+expires+' path=/';
tryStartPlayer('p_'+id);
}// ]]>
</script>
Inserting the following JavaScript code after the media tag in the article. This code simply calls the previously defined function. For the ID parameter, it uses the same value that has been specified as the attribute divid in the media tag of the player.