Playing MP3 Issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Playing MP3 Issue

Post by Bigun »

I thought I had successfully found a way to play MP3's from a site and keep it from being downloadable.

Code: Select all

header('Content-Type: audio/mpeg');
header("Content-Disposition: attachment; filename=$newfilename");
readfile("$filepath");
Ignore the code above, read below

Played fine in Linux with mplayer...

But a friend of mine said it was an awful short song... like 3 seconds....

I booted into Windows.... sure enough.... it played 3 seconds and stopped...

Didn't play at all in IE.

Here's a link:
http://www.cybergrunge.com/play.php?song=13
Last edited by Bigun on Sat Sep 16, 2006 9:14 am, edited 1 time in total.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

Don't you just need to <embed> to prevent it from being saveable?

Code: Select all

<EMBED    SRC="filename.mp3" HEIGHT=60 WIDTH=144>
http://www.htmlcodetutorial.com/embedde ... EMBED.html
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

People can still look at the source and find the file...

The MP3's in question are stored in a directory that apache gives restricted access to. PHP has to readline it from that directory to the listener's audio player.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

I just now saved that whole mp3 file - 8.07 MB - servo.hatred :)

anything that reaches client side can be saved on his computer... it can be mp3, flash, video, audio, css, virtually any thing that is served to client. you can make the job tough but not impossible...

in this case i'd suggest a flash player for your mp3.. just to harden the case...
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

Code: Select all

header('Content-Type: audio/mpeg');
header("Content-Disposition: attachment; filename=$newfilename");//this line allows the save!
readfile("$filepath");

loose the content disposition header
When Internet Explorer receives the header, it raises a File Download dialog box whose file name box is automatically populated with the file name that is specified in the header. (Note that this is by design; there is no way to use this feature to save a document to the user's computer without prompting him or her for a save location.)

Code: Select all

header('Content-Type: audio/mpeg');
readfile("$filepath");
Opens it straight to your default mp3 player
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

Whoops.... my bad... I pasted the code from my download.php.... not play.php:

Code: Select all

header('Content-Type: audio/mpeg');
readfile("$filepath");
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

n00b Saibot wrote:I just now saved that whole mp3 file - 8.07 MB - servo.hatred :)

anything that reaches client side can be saved on his computer... it can be mp3, flash, video, audio, css, virtually any thing that is served to client. you can make the job tough but not impossible...

in this case i'd suggest a flash player for your mp3.. just to harden the case...
Even still, doesn't the flash player code contain the path of the MP3?
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

I also have a .htaaccess file with the following in it:

Code: Select all

deny from all
When the applet loads up it can't access the file (duh)

You see the delima I'm in
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Bigun, If you need to send it to the client... the client can save the file... the only (possible) way to prevent it would be embedding the mp3 with some sort of (yuk!) DRM...
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Bigun wrote:
n00b Saibot wrote:I just now saved that whole mp3 file - 8.07 MB - servo.hatred :)

anything that reaches client side can be saved on his computer... it can be mp3, flash, video, audio, css, virtually any thing that is served to client. you can make the job tough but not impossible...

in this case i'd suggest a flash player for your mp3.. just to harden the case...
Even still, doesn't the flash player code contain the path of the MP3?
like I said... you can make the job tough but not impossible...
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

:?

Damned if I do... damned if I don't
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Why not just shorten the file length, that way you

a.) give a sample instead of the whole song
b.) save bandwidth which can get chewed up very fast with large files getting downloaded all the time
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

I went with the flash player idea... if someone wants to go through that much trouble without signing up for a free account, more power to them.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Gotta balance time with how much you care!
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

GUH!

It seems while I am trying to play MP3's using this button player it just stops playing the MP3 when it feels like.

See if it happens to anyone else:


http://www.cybergrunge.com/view.php?viewband=b-9
Post Reply