PDA

View Full Version : Problems with secure audio streaming...


ross987
07-04-2007, 04:29 PM
Hi

I'm not sure if this is exactly the right forum...

Basically I have set up streaming audio on my webpage, in the form of a flash "jukebox", where a user can skip tracks etc. This has all gone fine, and currently the player works.

I have stored all the info about the songs in a mysql database, and I use flash to dynamically load the playlist when the user press "next" + "back" etc (via php).

My main problem is despite storing the info in a database, i still feel that it is very unsecure, as all mp3's are left in a directory (and if you knew the name of it you could just download the mp3). How would i go about protecting the mp3's so that say, only the swf file could access them and all other connections are rejected?

I have looked into this for a little while, using php/htaccess seem like possible ways to protect the audio, but I have stumbled on a problem with flash.

I am under the impression that all SWF files are actually downloaded to the browsers cache, so when they are listening to my audio they are using a local copy of the SWF file, which means i cannot specify that "myserver.com/swffile.swf" is the only file able to access my songs (it would in fact be more like "c:\doc&settings\user\temp internet files\file.swf").

Sorry for the long post but i thought its better to fully explain the "big picture".

Many Thanks

Ross

CyanBlue
07-04-2007, 05:22 PM
Howdy and Welcome... :)

What you first need is to store the MP3 files off of the web server and place it to where HTTP call cannot retrieve... Then, you use PHP to grab the specific MP3 file and post it back to the request call made from the Flash/PHP... Well... That's the big picture anyways... ;)

I believe there are several threads that talks about that in this Server side forum, and you will find whole lot more if you check out the PHP specific forums such as PHPBuilder.com and such...

ross987
07-05-2007, 11:23 AM
Hi, thanks for the quick response. I actually thought I needed to do this and had found scripts which do this for image files (to prevent hotlinking), but could not be applied to any file type as they use image specific functions.

After reading your post i tried searching using some other terms and bingo i found the script i needed (at phpbuilder.com (http://www.phpbuilder.com/tips/item.php?id=5)).

Thanks for the quick reply and sending me on the right path.

Ross

CyanBlue
07-05-2007, 01:37 PM
Cool... Thanks for sharing the information... ;)

ross987
07-05-2007, 04:25 PM
Ok, so as usual with programming, solving 1 problem uncovers more!

I have modified it now so my php serves an mp3 from outside the document root. For testing purposes, it serves 1 specific file , and only that 1 file.

Previously my flash audio player would call an mp3, instead it now calls rsong.php, which basically outputs an mp3.

2 issues I have come across:

1) when accessing rsong.php directly, my computer tries to download the mp3 file (which is fine, i set the headers up to do this). When downloaded, the song is perfect and intact. However when i change the headers to the correct mp3 headers my browser tries to play it in the browser window (using quicktime). The problem is it only plays about the first second and says the track is finished (THIS ISSUE MIGHT BE THE CAUSE OF THE NEXT ONE :S).

2) my flash mp3 player has a progress bar, saying how far through the song it is/ how much has been downloaded so far etc. These are represented in your typical kind of youtube way with sliding bar, progress meter etc.

When i load rsong.php into it using either way above, the song will be more delayed in starting to play, but it will play all the way through :D ;
BUT, the progress bar jumps about, infact it goes in reverse for a while (when you move the current position to half the way through the song - meanwhile the song behaves how you would expect it to (in terms of sound)).

I'm thinking that maybe the slider keeps jumping because the flash script is updating the length/size of the mp3 and maybe there is an issue here as it is a php file not mp3.

Does this sound like anything anyone has come across in flash before or maybe i am simply retrieving the mp3 in the wrong way, although I have tried MANY different scripts which do the same thing.

Thanks again, and sorry for the rant, hope you understand me.

CyanBlue
07-05-2007, 06:35 PM
I honestly did not have a chance to play with such case, so I might not be of much help, but I think that has to do with how much is downloaded into the Flash...

My suggestion is to get the length of the MP3 file from the database, which you have to save it in the first place, and have Flash wait until that much is downloaded so that it will start playing, or even display the download progress bar based upon that value instead of the one you get from within the Flash... and I think that will resolve most of your problem, I hope... ;)