PDA

View Full Version : help loading FLV with PHP


pasiphilo
07-25-2007, 04:07 PM
Gang,

I've been unable to find any solution - or even a solid explanation - for this problem anywhere.

I've built a custom FLV player that needs to rely on a PHP script to serve it FLV files in order to control access to those files. My player uses the FLVPlayback component.

My actionscript makes a call like this to the PHP script:

my_player.contentPath = "http://testserver/resource.php?id=12345"

I've also tried...

my_player.load("http://testserver/resource.php?id=12345");

The resource.php code in question looks something like this:

header('Content-Type: video/x-flv');
readfile("my_video.flv");

When tested, the FLVPlayback component simply won't accept the FLV served up to it in this way. It will load if targeted directly from Flash, so I know my actionscript works.

(I did find that the far less robust Video object - in conjunction with NetStream class - does load the FLV from my PHP script, but using this player creates a whole whack of other problems for me, including a usability issue due to an apparent inability to let me measure loading progress by comparing bytesLoaded to bytesTotal - again, seemingly the fault of the PHP script, since loading directly from the file system works properly.)

So here's the question: How can I get my PHP script to serve the FLV to my FLVPlayback-based player?

Whoever can help me solve this will have my eternal respect and admiration.

Thanks,

J

CyanBlue
07-25-2007, 04:09 PM
Howdy and Welcome... :)

What is the MIME type for the FLV file set to on your server???
If you are on Windows 2003 server, you might need to set it manually...
http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19439&sliceId=1

pasiphilo
07-25-2007, 04:50 PM
Hi, CyanBlue,

I'm running Apache on my local Windows box. I've tried setting the MIME type to "video/x-flv" both in my httpd.conf and my .htaccess file with the following:

AddType video/x-flv flv

I've tried my Flash/PHP app both on my local system and on two different remote Apache/Linux hosts with the above setting, but without success.

J

CyanBlue
07-25-2007, 05:12 PM
Do you have the URL where I can try to hit???

pasiphilo
07-25-2007, 05:59 PM
I have a rudimentary version of the app, available in two flavours:

This one calls the FLV directly from the file system, and therefore works. (This is just here to show you what you should see.)
http://www.gaminggeek.com/test/test_1.php

This one - the one I need to make work - calls the resource.php, which is supposed to serve up the FLV:
http://www.gaminggeek.com/test/test_2.php
As you'll notice, the video doesn't load.

You can load resource.php directly here:
http://www.gaminggeek.com/test/resource.php

J

CyanBlue
07-25-2007, 07:23 PM
Hm... You totally got me on that... :(

pasiphilo
07-26-2007, 03:46 PM
Thanks to etully at phpbuilder.com, I arrived at the following solution.

The root cause was that the FLV served up by the PHP script was being sent to Flash as a .php file, which the FLVPlayback component doesn't like. The root solution, therefore, was to rename the PHP script with a .flv exension, as outlined below.

The files in the "resources/" folder:
resources/
-- .htaccess
-- test.xxx (a renamed FLV file)
-- resource.flv (a renamed PHP script)

The .htaccess file:
AddType application/x-httpd-php .flv

The PHP script (renamed to "resource.flv"):
$filename = "test.xxx";
header('Content-Type: video/x-flv');
header('Length: ' . filesize($filename));
header('Content-Disposition: attachment; filename="'.$filename.'"');
$fd = fopen($filename, "r");
while(!feof($fd)) {
echo fread($fd, filesize($filename));
flush();
}
fclose ($fd);

The salient ActionScript:
//my FLVPlayback compontent instance is named "video"
video.load("http://www.myserver.com/resources/resource.flv");

There may be some extraneous headers now being sent in the PHP script, but at least it works.

J

CyanBlue
07-26-2007, 05:02 PM
DOH!!! That just go totally against with the idea of MIME type... That's something, ain't it???

Thanks for providing the solution... Really appreciate it and I am sure there are others who will do the same... :)