This is a message.

autoPlay Based On Cookie Created Dec 17, 2008

This thread is solved

Views: 3487     Replies: 7     Last reply Jan 8, 2012  
You must login first before you can use this feature

cameronbprince

Posts: 6

Registered:
Oct 13, 2008

autoPlay Based On Cookie

Posted: Dec 17, 2008

Hey guys,

I wrote this code to autoPlay the video only the first time the page is loaded. Is there a better way to accomplish this? JSON is nice, but doesn't seem very friendly to being programmatically updated.

Thanks,
Cameron



var config = {
	logo: {
		url: '/img/misc/logo.png',
		fullscreenOnly: false
	},
	plugins: { 
		controls: { 
			url: '/flash/flowplayer.controls-3.0.1.swf',
			backgroundColor: '#343434',
			backgroundGradient: 'low',
			fontColor: '#ffffff',
			timeColor: '#c2d114',
			autoHide: 'never',
			progressColor: '#c2d114',
			bufferColor: '#313131',
			buttonColor: '#212121',
			buttonOverColor: '#313131'
		} 
	}
};

if (readCookie('TU-movie1'))
	supplement = {
		playlist: [
			{
				url: '/video/movie1.jpg', 
				scaling: 'orig'
			},
			{
				url: '/video/movie1.mp4',
				autoPlay: false, 
				autoBuffering: true 
			}
		],
	};
else
{
	supplement = {
		playlist: [
			{
				url: '/video/movie1.jpg', 
				scaling: 'orig'
			},
			{
				url: '/video/movie1.mp4',
				autoPlay: true, 
				autoBuffering: true 
			}
		],
	};
	createCookie('TU-movie1',1,365);
}

var i;
for (i in supplement)
	config[i] = supplement[i];

$f("video-player", "/flash/flowplayer.commercial-3.0.1.swf", config);


cherdt

Posts: 21

Registered:
Sep 23, 2008

» autoPlay Based On Cookie

Posted: Dec 17, 2008

Reply to: autoPlay Based On Cookie, from cameronbprince
Your solution makes sense to me, although you could shorten it a bit like this:

var firstTimeVisitor;
if (readCookie('TU-movie1')) {
	firstTimeVisitor = false;
} else {
	firstTimeVisitor = true;
	createCookie('TU-movie1',1,365);
}

supplement = { 
  playlist: [ 
    { 
      url: '/video/movie1.jpg',  
      scaling: 'orig' 
    }, 
    { 
      url: '/video/movie1.mp4', 
      autoPlay: firstTimeVisitor,  
      autoBuffering: true  
    } 
  ], 
};

cameronbprince

Posts: 6

Registered:
Oct 13, 2008

» » autoPlay Based On Cookie

Posted: Dec 17, 2008

Reply to: » autoPlay Based On Cookie, from cherdt
Great... This is exactly what I was looking for.

Thanks!

omb70

Posts: 27

Registered:
Nov 2, 2010

» » autoPlay Based On Cookie

Posted: Jan 12, 2011

Reply to: » autoPlay Based On Cookie, from cherdt
Nice code cherdt! Any idea how the code could be changed so that the video only be played once per session or per day?