Embedded Flash Player is not working from another domain (Cross-Domain swf access )

July 18th, 2008 by Sajith M.R

When I used an flv player for my website www.amvizone.com, the main problem I faced was the external embedding. So I provided the iframe embedddng method instead of embedded object like youtube. The problem was the embedded flash player only worked with the my domain (where the player.swf is placed). When I put the same embedded code with src points to http://www.amvizone.com/player.swf from another domain, the player did not work.

FLV Player

Recently My Friend Rahul (He is the master in flash and action scripts) gave me a solution for this. That is, you have to add cross-domain policy to your server to server the swf file to other domains.

When a Flash document attempts to access data from another domain, Flash Player automatically attempts to load a policy file from that domain. If the domain of the Flash document that is attempting to access the data is included in the policy file, the data is automatically accessible.

You have to create a file, crossdomain.xml and place in the root folder or any other folder where content is placed. The data in the crossdomain.xml file is shown below:

<?xml version="1.0"?><!-- http://www.foo.com/crossdomain.xml -->

<cross-domain-policy>

<allow-access-from domain="www.friendOfFoo.com" />

<allow-access-from domain="*.foo.com" />

<allow-access-from domain="105.216.0.40" />
</cross-domain-policy>

The above configuration allow any subdomains of foo.com or a particular ip 105.216.0.40 or www.friendOfFoo.com

If you need to provide access to all domains , you can use the following xml:

<?xml version="1.0"?>

<!-- http://www.foo.com/crossdomain.xml -->

<cross-domain-policy>

  <allow-access-from domain="*" />

</cross-domain-policy>

Courtesy: Adobe.com

And special thanks to Rahul for sharing the information

For details: click here

Regards

Sajith M.R

Wordpress Announcement - Plugin

June 24th, 2008 by Sajith M.R

Wordpress Announcement Plugin

Do you wanna inform any important news or message to your readers ? Here is a simple plugin, Wordpress Announcement Plugin.

Download the plugin from : http://downloads.wordpress.org/plugin/announcement.zip

Go to Admin > Plugin > and activate announcement plugin. After that, go to options and select Announcement. By default the plugin will be inactive. You have to set your announcement and activate the announcement by checking ‘Active’ checkbox.

Never Forgot to Run the Announcement. By Default the Announcement will be inactive

Enough !!! You visitors can now see your announcement. It will be displayed only one time for a particular user .

(If you want to see the announcement again, for testing purpose, Clear browser cookies, or atleast cookies from your blog. Otherwise you have to wait another 24 hours to play the announcement again)

The plugin is created with cute design and animation. It will never interrupt your blog reader.

Regards

Sajith

Requirements for a Video Website

June 23rd, 2008 by Sajith M.R

If you are planing to start a video website like youtube, here is some things to keep in mind.

FLV PLAYER
========

You know in now a days most of the video streaming websites use flash player for video streaming. The video file is in flv format. So you need a flash video player for this purpose.
You can download a free flash / flv player from : http://www.jeroenwijering.com/?item=JW_FLV_Player
or http://flowplayer.org/

FORMAT CONVERSION
===============

Now you need videos in flv file format. In normal cases, most of the videos uploaded by an user will be in avi, dat ,mpg,mp4 or 3gp. So you need a flv converter. You can use either ffmpeg library or mencoder for this purpose

Here is a sample video emmbedding method.



codebase=”http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,18,0″
width=”450″ height=”375″ id=”/YouTube_video/youtube” align=”middle”>




bgcolor=”#ffffff” width=”450″ height=”375″ type=”application/x-shockwave-flash”
pluginspage=”http://www.macromedia.com/go/getflashplayer” />;

Here src parameter points the swf file, the flash palyer and video parameter points the flv file. This is the format of player i used in http://www.amvizone.com

ffmpeg also can be used for making thumbnails and video watermarking

STORAGE and BANDWIDTH
=====================

Where would you save flv files. In yourown server ? If there is a minimum number of videos, your server might handle it. But consider the case having a large number of videos, your server bandwidth will get used soon. So we have to switch into a CDN (Content Data Network) like amazone S3. What you have to do is just register with any CDN website and use their webservices for uploading and manipulating your video files. These CDN have very reasonable cost for the bandwidth usage and storage space.

Comment here if any queries
Regards

Sajith M.R

Download Youtube Videos using PHP Code

May 29th, 2008 by Sajith M.R

If you want to get the FLV file of any youtube video url using php code, here is the solution.

If you are a PHP Programmer and if you are working with any video website, and if you need to grab videos (FLV files) from youtube and to put it yourown site (not object embedding) , Download the Full Source Code given at the end of this article (ZIP)

I used this php code for the Youtube video download tool http://www.googleneedle.com


Here function getPatternFromUrl is nothing but, get the exact pattern of a particular video from any youtube video url format.

In the above case , it returns pzmP4UvZRa4

The function is below

function getPatternFromUrl($url)

 {

$url = $url.'&';

$pattern = '/v=(.+?)&+/';

preg_match($pattern, $url, $matches);

return ($matches[1]);

}

GetFlvFromYoutube is the main function here, which download the flv file from youtube pattern and saves to your local machine.
The function is below:

function GrabFlvFromYoutube( $pattern )
{

 require_once ("phptube.php");

 $tube = new PHPTube ();

 $flv_http_path = $tube->download($pattern) ;

 echo $flv_http_path;

 set_time_limit(0);

 $data = file_get_contents($flv_http_path);

 $new_flv_path = dirname(_FILE_).'/flvs/'.$pattern.'.flv' ;

 file_put_contents($new_flv_path, $data);

 return $new_flv_path ;

}

Download the fullsource code from this link given:

http://www.sajithmr.com/downloads/youtube-download-php.zip

Cross Browser Cookies

April 4th, 2008 by Sajith M.R

A normal html / web developer must be femilered with cookies and sessions. In normal case the cookie set by one browser cannot be access through another browser. Each browsers have its own space to store the cookie value. Thats why when you login your email account from one browser, if you go another browser , non of your preference will be available. This is the case of normal cookies.

HTTP cookies, or more commonly referred to as Web cookies, tracking cookies or just cookies, are parcels of text sent by a server to a web browser and then sent back unchanged by the browser each time it accesses that server. HTTP cookies are used for authenticating, tracking, and maintaining specific information about users, such as site preferences or the contents of their electronic shopping carts. The term “cookie” is derived from “magic cookie,” a well-known concept in UNIX computing which inspired both the idea and the name of HTTP cookies - Wikipedia

But what will do if you want to set a cookie which is to be accessed from different browsers , ie mozilla, safari, opera ,internet explorer share same cookie ??

Come back to the case of shock wave flie (swf ) or flash files. They also have privillages to set cookies in browser. Like html, it also have all the features in client side. Consider the cookie setting mechanism of a flash file. It is not on different places for different browsers. It is on a common file on your computer and no matter what the browser.

Think this thing also javascript can access flash object via normal javascript functions if swf provides provision for that. Then when rethink the whole stuff, if you set a cookie through flash , you can access it from any browser.

Cross browser cookies

See this post: http://www.nuff-respec.com/technology/cross-browser-cookies-with-flash

In this post Mr. Daniel Bulli explains it detaily. He is the big man here.

also see this link: http://www.ts0.com/crosscookie/example.html

A live example for cross browser cookie. Both of the sites provide source code of their implementation.

I also uploaded the source code as a backup. Download it from here: OpenID Integration PHP