Forum Moderators: coopster

Message Too Old, No Replies

Preventing download of mp3s.

         

bhuether

1:24 am on Mar 18, 2008 (gmt 0)

10+ Year Member



I have web site with guitar lessons. Only members can listen to lesson audio. The audio is not stored outside the public_html folder. Maybe that is the first thing I need to fix. In any case, here is how the playback happens (using the XSPF flash player)

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"
width="400" height="168" >
<param name="allowScriptAccess" value="sameDomain"/>
<param name="movie" value="http://www.mysite.com/xspf/xspf_player.swf?song_url=<?php echo $link; ?>&song_title=<?php echo $extitle; ?>"/>
<param name="quality" value="high"/>
<param name="bgcolor" value="#E6E6E6"/>
<embed src="http://www.mysite.com/xspf/xspf_player.swf?song_url=<?php echo $link; ?>&song_title=<?php echo $extitle; ?>"
quality="high" bgcolor="#E6E6E6" name="xspf_player" allowscriptaccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer"
align="center" height="168" width="400"> </embed>
</object>

If I place the audio in folder outside the webroot, what should I specify for the url? Would I use file://user/home/audio/audio.mp3? How exactly would I specify url if there really isn't url to the file?

thanks,

brian

venti

3:40 am on Mar 18, 2008 (gmt 0)

10+ Year Member



Yes, move the mp3s outside of the web root. Then have the url point to the "scripted" file with a url parameter for the mp3 file being requested.

Ex: example.com/mp3loader.php?id=satriani_rocks_2006

I don't know the specifics for PHP (Perl, CF, and JSP guy) but you should be able to lookup what code is needed to fetch the file via the file system and return it with the proper headers. Sorry I can't give you the exact code.

vincevincevince

4:11 am on Mar 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If outside the web-root doesn't work; create a .htaccess file to block all access to the files through the browser entirely. You then use e.g. PHP to stream the file to Flash as venti indicated:

<?php
//do membership check here (e.g. check cookie or session)
$filename="path_to_file/".intval($_GET[fileid]).".mp3";
header("Content-type: application/audio-mp3");
header("Content-length: ".filesize($filename));
$fh=fopen("w",$filename);
while ($data=fread($fh,1024)) { print $data; flush(); }
?>

Code untested; may contain bugs, but structure is right!

DrDoc

4:54 am on Mar 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$fh=fopen("w",$filename);

Well, two very important pointers. First of all, it goes filename first, then mode. But, more importantly -- you want to use "r" since you want read the file, not write to it!

$fh = fopen($filename, "rb");

[edited by: DrDoc at 4:55 am (utc) on Mar. 18, 2008]

vincevincevince

8:04 am on Mar 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Code untested; may contain bugs, but structure is right!

bhuether

6:12 am on Mar 20, 2008 (gmt 0)

10+ Year Member



I used the below example essentially. Seems to work well, but I am noticing that audio playback through the XSPF flash player will be choppy - sometimes the audio drops out every 5 seconds or so. Any advice on how to ensure smooth, uninterrupted audio playback?

thanks,

brian

vincevincevince

6:21 am on Mar 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Lower bit-rate at a guess; or a faster server; or a faster ISP. Audio dropping out is normally a problem with bandwidth somewhere along the line.