Click here to get back home

Serving local windows media files via PHP

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Serving local windows media files via PHP AeonOfTime 07-30-2008
Get Chitika Premium
Posted by AeonOfTime on July 30, 2008, 12:52 pm
Please log in for more thread options
Hi everyone,

I am working on a project where I have .wmv files stored outside of
the server's www root, and want to serve them via a custom web
interface. It's all on windows, and is only intended to work locally
on the physical machine it runs on (don't ask, the customer is
king...).

Right now I have a working prototype in which I use a PHP script
(called movie.php) to serve the target file. In the HTML page, I have
an OBJECT tag that refers to the script, like so:

<OBJECT ID="MediaPlayer" WIDTH="512" HEIGHT="384"
CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
STANDBY="Loading Windows Media Player components..."
TYPE="application/x-oleobject">
<PARAM NAME="FileName" VALUE="movie.php?fileID=12345">
<PARAM name="ShowControls" VALUE="true">
<param name="ShowStatusBar" value="true">
<PARAM name="ShowDisplay" VALUE="true">
<PARAM name="autostart" VALUE="true">
<EMBED TYPE="application/x-mplayer2"
SRC="movie.php?fileID=12345"
NAME="MediaPlayer"
WIDTH="512"
HEIGHT="384"
ShowControls="1"
ShowStatusBar="1"
ShowDisplay="1"
autostart="1"
pluginspage="http://www.microsoft.com/windows/windowsmedia/download/
default.asp">
</EMBED>
</OBJECT>

The movie.php script itself is pretty simple too (stripped down to the
essentials):

<?php

        $timeout = 60 * 60 * 24 * 2;
        header( 'Cache-Control', 'private, max-age=' . $timeout . '' );
        header( 'Pragma', 'private, max-age=' . $timeout . '' );
        header( 'Expires', gmdate( 'D, d M Y H:i:s', time() + $timeout ) . '
GMT' );
        header( 'Content-Type:video/x-ms-wmv' );
        readfile( $file );

?>

This gives me a working player, but the big downside is the player
won't let me skip the clips :(

The seek bar does not respond to any requests to skip ahead, and
pausing the video resets it to the start. Any idea on how I can fix
this so I can skip ahead as much as I wish?

Thanks a lot!

Posted by petersprc on July 30, 2008, 3:53 pm
Please log in for more thread options
Hi,

Seeking usually involves a partial GET request (http://www.w3.org/
Protocols/rfc2616/rfc2616-sec14.html#sec14.35).

You could handle the range request in your script and send the byte
range specified in $_SERVER['HTTP_RANGE'] along with appropriate
headers. Example here: http://us2.php.net/manual/en/function.fread.php#84115

Alternatively, you can let Apache send the requested part directly by
using mod_rewrite and a map containing authorized sessions. Good
example here: http://bytes.com/forum/thread10523.html

The first is more flexible in terms of authorization and logging etc.
The second method would have slightly better performance, but I
wouldn't worry about it unless you're handling very high loads.

Regards,

John Peters

> Hi everyone,
>
> I am working on a project where I have .wmv files stored outside of
> the server's www root, and want to serve them via a custom web
> interface. It's all on windows, and is only intended to work locally
> on the physical machine it runs on (don't ask, the customer is
> king...).
>
> Right now I have a working prototype in which I use a PHP script
> (called movie.php) to serve the target file. In the HTML page, I have
> an OBJECT tag that refers to the script, like so:
>
> <OBJECT ID="MediaPlayer" WIDTH="512" HEIGHT="384"
> CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
> STANDBY="Loading Windows Media Player components..."
> TYPE="application/x-oleobject">
> <PARAM NAME="FileName" VALUE="movie.php?fileID=12345">
> <PARAM name="ShowControls" VALUE="true">
> <param name="ShowStatusBar" value="true">
> <PARAM name="ShowDisplay" VALUE="true">
> <PARAM name="autostart" VALUE="true">
> <EMBED TYPE="application/x-mplayer2"
> SRC="movie.php?fileID=12345"
> NAME="MediaPlayer"
> WIDTH="512"
> HEIGHT="384"
> ShowControls="1"
> ShowStatusBar="1"
> ShowDisplay="1"
> autostart="1"
> pluginspage="http://www.microsoft.com/windows/windowsmedia/download/
> default.asp">
> </EMBED>
> </OBJECT>
>
> The movie.php script itself is pretty simple too (stripped down to the
> essentials):
>
> <?php
>
> $timeout = 60 * 60 * 24 * 2;
> header( 'Cache-Control', 'private, max-age=' . $timeout . '' );
> header( 'Pragma', 'private, max-age=' . $timeout . '' );
> header( 'Expires', gmdate( 'D, d M Y H:i:s', time() + $timeout ) . '
> GMT' );
> header( 'Content-Type:video/x-ms-wmv' );
> readfile( $file );
>
> ?>
>
> This gives me a working player, but the big downside is the player
> won't let me skip the clips :(
>
> The seek bar does not respond to any requests to skip ahead, and
> pausing the video resets it to the start. Any idea on how I can fix
> this so I can skip ahead as much as I wish?
>
> Thanks a lot!


Posted by C. (http://symcbean.blogspot.c on July 31, 2008, 7:41 am
Please log in for more thread options
> Hi everyone,
>
> I am working on a project where I have .wmv files stored outside of
> the server's www root, and want to serve them via a custom web
> interface. It's all on windows, and is only intended to work locally
> on the physical machine it runs on (don't ask, the customer is
> king...).
>
> Right now I have a working prototype in which I use a PHP script
> (called movie.php) to serve the target file. In the HTML page, I have
> an OBJECT tag that refers to the script, like so:
>
> <OBJECT ID="MediaPlayer" WIDTH="512" HEIGHT="384"
> CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
> STANDBY="Loading Windows Media Player components..."
> TYPE="application/x-oleobject">
> <PARAM NAME="FileName" VALUE="movie.php?fileID=12345">
> <PARAM name="ShowControls" VALUE="true">
> <param name="ShowStatusBar" value="true">
> <PARAM name="ShowDisplay" VALUE="true">
> <PARAM name="autostart" VALUE="true">
> <EMBED TYPE="application/x-mplayer2"
> SRC="movie.php?fileID=12345"
> NAME="MediaPlayer"
> WIDTH="512"
> HEIGHT="384"
> ShowControls="1"
> ShowStatusBar="1"
> ShowDisplay="1"
> autostart="1"
> pluginspage="http://www.microsoft.com/windows/windowsmedia/download/
> default.asp">
> </EMBED>
> </OBJECT>
>
> The movie.php script itself is pretty simple too (stripped down to the
> essentials):
>
> <?php
>
> $timeout = 60 * 60 * 24 * 2;
> header( 'Cache-Control', 'private, max-age=' . $timeout . '' );
> header( 'Pragma', 'private, max-age=' . $timeout . '' );
> header( 'Expires', gmdate( 'D, d M Y H:i:s', time() + $timeout ) . '
> GMT' );
> header( 'Content-Type:video/x-ms-wmv' );
> readfile( $file );
>
> ?>
>
> This gives me a working player, but the big downside is the player
> won't let me skip the clips :(
>
> The seek bar does not respond to any requests to skip ahead, and
> pausing the video resets it to the start. Any idea on how I can fix
> this so I can skip ahead as much as I wish?
>
> Thanks a lot!

Don't use wmv.

In addition to solving the player problems, you'll reach a wider
audience and prevent leeching by using mpeg and Flash - see
http://www.webvideozone.com/public/171.cfm

C.

Similar ThreadsPosted
transparenty serving media stream November 23, 2005, 12:18 am
Serving Files with PHP November 17, 2006, 2:49 pm
Securely serving files February 11, 2006, 5:56 am
Serving files and redirecting using headers. November 30, 2004, 10:59 am
Serving files stored on an IMAP server October 3, 2006, 12:34 pm
Serving Large Data From Files or From Blobs February 15, 2008, 12:44 pm
Using local php.ini files July 25, 2006, 12:58 am
link to local files through a dynamic page February 27, 2006, 4:42 am
PHP and Windows INI files April 16, 2005, 3:47 am
Automatic Download of Files using application/save on Windows XP SP2 Browsers September 27, 2004, 10:19 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap