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

Forums

/

JWPlayer and Amazon Cloudfront Private Content

10 replies [Last post]

Amazon CloudFront recently began a service which gives the ability to deliver content in a private fashion. The resulting URI gets very long due to the private key that is delivered to access the content. JWPlayer does not seem to handle the exta long URI.

I checked out the other threads related to long URIs but most of them seemed to be concerned with the + sign encoding conversion. The private key does not contain any + signs but still will not play the underlying video.

I recieve the video name from a stored cookie and couple it with the privacy signature. I have confirmed that the video will play correctly without including the privacy code. I have also confirmed that a single document will serve correctly from Amazon using the privacy code if JWPlayer is not used (ie simple private file access). So it has to be the extra long privacy content.

Any suggestions???

<script type='text/javascript' src='../scripts/JWPlayer/swfobject.js'></script>
<script type='text/javascript'>
var video=Get_Cookie("sodemand");
var s3file="http://test.cloudfront.net/"+video+"?Policy=<policy string>&Signature=<privacy signature>&Key-Pair-Id=<key pair ID>";

var s1 = new SWFObject('../scripts/JWPlayer/player.swf','player','712','420','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addVariable('file',s3file);
s1.addVariable('image',<image location>);
s1.addVariable('autostart','true');
s1.write('preview');
Delete_Cookie(<cookie information>);
</script>

urlencode the file URI so it doesn't get confused with the flashvars stacking characters.

From Bobby van der Sluis, one of the developers of SWFObject.

"SWFObject complies with Adobe's usage of
flashvars, so for both static and dynamic publishing we adhere to the
same flashvars syntax as Adobe (or Macromedia) has originally defined.

According to these syntax rules certain special characters and the
symbols = and & cannot directly be used inside flashvars values (the
latter because they are used to stack the flashvars themselves). You
can workaround this issue by escaping these characters before passing
them as flashvar values.

Our documentation refers to Adobe's documentation:
http://kb2.adobe.com/cps/164/tn_16417.html

This behavior is documented in Q9 of our FAQ:
http://code.google.com/p/swfobject/wiki/faq

Which in its turn refers to:
http://kb2.adobe.com/cps/141/tn_14143.html"

var s3file = <strong>encodeURIComponent(</strong>"http://test.cloudfront.net/"+video+"?Policy=<policy string>&Signature=<privacy signature>&Key-Pair-Id=<key pair ID>"<strong>)</strong>;

The length doesn't matter, I've tested using more than 2,000 characters with no issues (well — there IS a 99,999 character limit in the player code — so don't get carried away).

Read the Tutorial Embedding Flash on the Tutorials page.

I had given that a try based on a suggestion from one of the other forum items. However, I urlencoded it within the addVariable syntax. Like this...

s1.addVariable('file',encodeURIComponent(s3file));

I am not sure what the implications of doing the encoding within the addVariable are versus directly on the variable.

The result of the original was a 0:2048 error. I will try moving the encoding to the variable declaration.

You can do the urlencoding when the variable is declared or within the SWFObject code. It's the same either way.

Since you're not showing us a real URI, we can only guess.

If your URI doesn't end with a recognized media file extension, be sure that you tell the player the type of media that it will be receiving.

s1.addVariable('type', 'video');

Sammie...Sorry for not replying for such a long time but I got pulled away from this project for another and I am just getting back to it now. I would like to restart this conversation to get to the bottom of why Cloudfront Privacy is not working...

Attached you will find the code that I am using for the JWPlayer (including the real URI). I found a few other articles that indicated that I should escape &, = and one other character but I don't know if I need to escape the individual characters and then encodeURIComponent or simply encodeURIComponent the entire string. I have tried the second with no success but not the first.

Maybe you can give me a little more detail related to the best way to overcome the special character issue.

One other question...Related to your comment on media recognition...Since the Signature and Key Pair ID are the last content in the filename, does this mean that I would need the type variable. What I mean is, the file is type FLV but since the .flv is not the last thing in the file URI does that mean I would need the type variable?

Thanks for any help you can provide...
Al

<p align="center" id='preview'>
<script type='text/javascript' src='../scripts/JWPlayer/swfobject.js'></script>
<script type='text/javascript'>
var video=Get_Cookie("<cookie_name>");
var s3file="http://d1l3pltzzodv4i.cloudfront.net/"+video+"?Policy=eyJTdGF0ZW1lbnQiOlt7IkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTI1ODY4OTE5N319fV19&Signature=bnCxcDiLmuktq1EVWt1a9qQmBrDCPsjJh18vqJuY6IJi~c0qcjGQOBJRnE5t-itjvQIc6IOZ859EFGwsom4DaxLXvCnHurheXPqCoApjR9NR5HV24YdI58yr44A8kzidVm~nXn7KXN6LfNs95HkaKjKSrYuHvzsjQN5tuYRtZaE_&Key-Pair-Id=APKAJ3T6AVWRWNT4ESVP";

var s1 = new SWFObject('../scripts/JWPlayer/player.swf','player','712','420','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addVariable('file',s3file);
s1.addVariable('image','http://<site_name>/images/sod_videoskin.jpg');
s1.addVariable('autostart','true');
s1.write('preview');
</script></p>

Did you ever get this working?

James

Here's where I am on this. You seem to have missed the streamer out. I have no problem playing the video, I just can't seem to get the policy to work correctly:

<script type='text/javascript'>
var so = new SWFObject('player.swf','ply','720','430','9','#ffffff');
so.addParam('allowfullscreen','true');
so.addParam('allowscriptaccess','always');
so.addParam('wmode','opaque');
so.addParam('type','video');
so.addVariable('streamer','rtmpe://sxxx...xxxxx3b.cloudfront.net/cfx/st');
so.addVariable('file',encodeURIComponent('mp4:1_Minute_Short.mp4?Policy=xxxxxxxx.....xxxxxxGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjEyNzA1MDE0NDZ9fX1dfQ__&Signature=hFpBiMxxxxxxxxx......xxxxxxxxxxyhfbQuFfCLlap8y25M7nnNx-3dosUdj7I_&Key-Pair-Id=APKAIxxxx....xxxxxxVDKOXIA'));
so.write('mediaspace');
</script>

It turned out to be easy in the end after some RTFM time.

The only problem in that you can't seem to prevent hot-linking although you can do time-expiring urls which are of some interest.

The CDN is super fast and we are very impressed with performance and price.

James

Thanks James, could you post the final working code?

I notice that in the last codepart the filename starts with "mp4:....".
When is a protocol necessary for the file-variable?
And when it is an FLV-file does it need to be flv:... ???

I'm facing the same issue James. Can you or anyone here tell me what the final fix was?