On Wed, November 15, 2006 12:01 pm, Brian Dunning wrote: > I'm trying to route all my MP3 requests through a brief PHP script to > log the downloads to a database, and then I want to output the MP3 > exactly as if the browser had requested it normally. So far I haven't > found headers that will serve it normally; it either wants to > download it as an attachment or an application. I want the browsers > to treat it however they normally treat MP3's, usually playing in the > browser window. Here's what I'm doing: > > (my MP3 files are all named podcast-xxxx.mp3) where $id is the xxx: > > header('Content-Type: application/octet-stream'); application/octet-stream guarantees a download, and has been a documented feature from the inception of HTTP specifications as such: http://richardlynch.blogspot.com The correct mime type for an MP3 is: audio/mpeg For an m3u playlist: audio/mpeg-url > header('Content-Disposition: attachment; > filename=podcast-'.$id.'.mp3'); This is made-up MS Outlook/IIS bullcrap that will only cause you grief in the long run. Get rid of it. You may get it to work "today" on the browser you try out, but you'll find somebody sooner or later that this just messes up. See the Rant URL above for excruciating detail on this one, and on how to get the filename to be what you want, no matter how stupid the browser is. And the stupidity of browsers is legion. > $size = filesize('audio/podcast-'.$id.'.mp3'); > header('Content-Length: '.$size); > readfile('audio/podcast-'.$id.'.mp3'); readfile(), depending on your PHP version, is going to suck in the whole MP3 before it starts spewing out bytes. If the MP3 is of any length at all, and your server is even moderately busy, the player will get tired of waiting, and time out, because PHP is reading a 4Meg file into RAM before it sends ANY of it to the player. You would be better served here to do an fopen/fread loop and spew out a good-sized chunk (say, 2K at a time) to make sure the player doesn't give up. Plus, mp3 can be decoded and begin playing when only part of the content has arrived, so you get much more responsive audio this way. You do risk that your server can't keep up with the player, and the audio gets that "choppy" effect where the player has to wait on the server. But users actually expect that to happen, to some degree, and most of them have enough of a clue to set their buffer higher or pause the playing and wait, rather than just abandon content that they want. With readfile() they just assume your MP3 is "gone" or "dead" or "broken" and seek content elsewhere. You may also want to consider snagging the very cool ID3 PHP library which will let you prepend the ID3v2 tags so you can get the artist image in the "Now Playing" box at the bottom left of iTunes, without actually munging your MP3 file. You also will want to read this to generate the RSS file which lists ALL your podcast MP3s in one giant XML document which makes an actual "podcast" http://www.apple.com/itunes/store/podcaststechspecs.html as having a bunch of MP3s laying around doesn't really make it a podcast, much to my dismay... Actually, my current problem is that Apple seems to have a very limited "vision" of what a podcast could be :-( Apparently, I can't have several years' worth of daily 30-song playlists as a podcast. :-( :-( :-( Feel free to contact me off-list for any more info on this stuff -- This is one area where I actually *DO* know what I'm talking about :-) http://uncommonground.com/ has about 2000 audio files available to the public, and another 63,000 that the artists have not yet chosen to be released... I'm working on getting more artists to be more active about releasing more of their audio there, but even a couple thousand songs recorded "live" for your listening pleasure is something. It's all Acoustic stuff, so if you're only into Death Metal, Industrial or whatnot, don't bother. But lots of singer/songwriter, "unplugged" pop rock, and that sort of stuff. Occasional "acoustic blues" or "folkie-folk" (not so much, really) or even some jazz here and there... Playlist on the homepage changes daily, and will be a podcast as soon as I figure out an optimum way to shoehorn the content into the very limited podcast form.... http://uncommonground.com -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php