Video Autoplay - Geeks to Go Forums

Jump to content

Log in Register Register Malware removal guide How it works

Video Autoplay How to set the video to auto play only once per visit (per visitor)

#1 jalternet

  • Group: Member
  • Posts: 2
  • Joined: 17-February 10

  Posted 17 February 2010 - 06:00 PM

Hi,

I have been looking for an answer for this problem for a longer time already....

my site is http://smarterealestate.com

I have one video set up to auto play once the page is visited or refreshed....

here is the code I have use:

<embed src="http://www.youtube.com/v/z435EriT9eY&hl&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="460" height="340"></embed>


.................


I hope somebody can show me a way to configure the video to only play once (for the first visit) --- so when the page is opened again, the video will not auto play anymore.

#2 TheBug

  • Group: Member
  • Posts: 28
  • Joined: 16-February 10

Posted 19 February 2010 - 07:44 PM

You can use JavaScript to set a cookie that video has been played once. Read that cookie, it you get it, do not autoplay. Here is a sample. The cookie expires after number of days I have set days = 7. So after 7 days the video will autoplay again. Change var days = 7; if you want.

<script language="Javascript">
function played(){
	var ca = document.cookie.split(';');
	for(var i=0; i<ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf("played=") == 0) return 1;
	}
	var date = new Date();
	var days = 7;
	date.setTime(date.getTime()+(days*24*60*60*1000));
	document.cookie = "played=1"+"; expires="+date.toGMTString()+"; path=/";
	return 0;
}
if(played()==0){
	document.write("<embed src=\"http://www.youtube.com/v/z435EriT9eY&hl&autoplay=1\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"460\" height=\"340\"></embed>");
}
else{
	document.write("<embed src=\"http://www.youtube.com/v/z435EriT9eY&hl\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"460\" height=\"340\"></embed>");
}
</script>


#3 jalternet

  • Group: Member
  • Posts: 2
  • Joined: 17-February 10

  Posted 19 February 2010 - 08:09 PM

Hi TheBug!

Thank you very much for the reply and the suggestion... I tried putting the sample you made on my site and it WORKED!!!!

The sad news, Internet Explorer can't display the video... how can this be fixed????

it worked with Google Chrome and Firefox...

Thanks! The cookies thing made it play once only....

#4 TheBug

  • Group: Member
  • Posts: 28
  • Joined: 16-February 10

Posted 19 February 2010 - 09:06 PM

Maybe you do not have Adobe Flash ActiveX installed for IE. Adobe Flash plugins are different for IE and other browsers.

http://www.filehippo...flashplayer_ie/

#5 ilreoagent

  • Group: Member
  • Posts: 1
  • Joined: 22-February 11

Posted 22 February 2011 - 02:58 PM

took a while to find this on google, thought it was a common thing, for me this works on all browsers except Chrome, I checked, and I don't have cookies blocked on chrome, so not sure why it plays on every visit in chrome.

Whoops nevermind, after a full play on Chrome it works!

For some reason on other browsers a full play isn't required, but a full play is required in Chrome...at least for me...Thanks TheBug

#6 drewdavid

  • Group: Member
  • Posts: 1
  • Joined: 28-November 11

Posted 28 November 2011 - 03:17 PM

Hi is there a way to use this with the new youtube embed codes? Thanks! I tried it and it was a no-go... (speaking if the iframe codes)

Thanks :)

Share this topic: