Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Video Autoplay


  • Please log in to reply

#1
jalternet

jalternet

    New Member

  • Member
  • Pip
  • 2 posts
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.c...&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.
  • 0

Advertisements


#2
TheBug

TheBug

    Member

  • Member
  • PipPip
  • 28 posts
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>

Edited by TheBug, 19 February 2010 - 07:44 PM.

  • 0

#3
jalternet

jalternet

    New Member

  • Topic Starter
  • Member
  • Pip
  • 2 posts
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....
  • 0

#4
TheBug

TheBug

    Member

  • Member
  • PipPip
  • 28 posts
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/

Edited by TheBug, 19 February 2010 - 09:07 PM.

  • 0

#5
ilreoagent

ilreoagent

    New Member

  • Member
  • Pip
  • 1 posts
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

Edited by ilreoagent, 22 February 2011 - 02:59 PM.

  • 0

#6
drewdavid

drewdavid

    New Member

  • Member
  • Pip
  • 1 posts
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 :)
  • 0

#7
tashmoister

tashmoister

    New Member

  • Member
  • Pip
  • 1 posts

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>

 

Hi there. Thanks for this script, its really helpful. I've just tried to have a video play on my website just once and not play or show up anywhere on the website after the visitor has seen it. This code works on firefox only and not on chrome or IE9. Is there a reason why it should not work? I've uploaded it onto a server so its not a local page.

 

 
<div id="player"></div>
 
<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;
}
 
var tag = document.createElement('script');
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
 
var player;
function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
        height: '1067',
        width: '1900',
        videoId: 'NR9bBqZCeqU',
playerVars: {'controls': 0 },
        events: {
            'onReady': onPlayerReady,
                'onStateChange': onPlayerStateChange
        }
    });
}
 
if(played()==0)
{
function onPlayerReady(event) {
    event.target.playVideo();
}
}
else{          
        stopVideo();
    }
 
var done = false;
 
function onPlayerStateChange(event) {        
    if(event.data === YT.PlayerState.ENDED) {          
        stopVideo();
    }
}
 
function stopVideo() {
    player.stopVideo();
    document.getElementById("player").style.height = "0px"; 
}
</script>

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP