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

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