MP3 Streaming on Demand?
Joe asks: "I've checked freshmeat a number of times, but I can't seem to find
any software that will stream mp3 files 'on demand'. Most software
for mp3 streaming (be it windows or unix) is based on the broadcast
model (shoutcast/icecast), where a fixed or growing playlist keeps
playing at all times. What I want is something that works on the 'play samples' model, where a sample of the tune is played automatically through a streaming protocol, rather than downloaded
and played once downloaded. Any such beast exist? If not, why not?"
"I suppose with enough fidgetting, one could write a cgi program (even as a /bin/sh script) that would start a new icecast process on a particular port, start the shout stream, and return to the browser the "playlist" that would signal the browser to start winamp/xmms on the appropriate port; the "start the shout stream" process would wait play silence for a few seconds before shouting the desired mp3 in order to give time to the player...but that seems rather kluge-like."
You stepped right over the solution without noticing it. Just make a CGI that will stream the MP3 directly to the player. Just make a normal playlist that points to your CGI (probably with a parameter for the desired soundfile). The playlist will be passed on to the mp3 player, which will then HTTP open the CGI, where you can start feeding the music data requested. Piece of cake.
-Billco, Fnarg.com
People have correctly pointed out that most "decent" mp3 players have had this functionality for a while. Winamp actually didn't have it at first if I recall. Other than that though, the ability to stream MP3 has been around -- and been done the same way -- since the very first MP3 player, WinPlay3. Winamp's method was more or less copied WP3's.
:)
Anyway, if you enter a URL in the Play Location: window of Winamp (ctrl-click on the eject button, or Ctrl-L), it will stream an MP3 at that location.
The bitch is that most web browsers will preempt streaming, waiting for the file to be fully downloaded before it passes it onto any helper app. This is in theory safer, but ya oughtta be able to turn off the deferral.
The answer of streaming from web links is to use M3U playlists for the file(s) you want to stream. The playlist contains the URL of the streamworthy file, and the web browser is none the wiser -- it passes the very small M3U onto the player, which then takes over the downloading of the file listed inside, streaming it in the meantime.
I suppose therefore you might want a script on your server that will generate M3U output on the fly for your online music collection. Such a script would be very simple -- in theory it only needs to output text data consisting of a URL to the actual file.
However, I usually just use "Copy Link Location" or "Copy Shortcut" from the right-click-over-link menu, and then paste it into the Winamp "Play Location" window. And there you have it, instant streaming on demand.
--
Terrorists can attack freedom, but only Congress can destroy it.
If we wanted to listen to something on our computer, we plopped a music CD in the CDROM tray. If we wanted to listen to something in a different part of our house, we didn't stream it to the computer in that room, we turned the volume up in the other room.
Nowadays, all you kids with your stream this, or rip that attitudes are causing those hard working record industry executives to get there panties in a bundle. The recording industry barely gets by on its razor thin profit margins, and any of this digital streaming might cause them to to go bust! If you weren't such lazy hooligans, you'd carry around your store bought CD around with you and listen to that.
-vax computer, vi, lynx. 'nuf said
http://www.lyra.org/greg/edna
It's a standalone http mp3 server. In one
python script. It sends
so that the mp3s are streamed. It can also
shuffle and play recursively.
Highly recommended.
Stephen.
(for the other end of things 'jack' is an
excellent ripper/encoder btw.)
As long as you are not looking for neato features like direct seek and realtime "live audio" streaming, http is a fine protocol for streaming mp3. Most decent mp3 players (xmms, mpg123 -b, sonique, winamp) buffer the input stream to handle bumps in the stream. Icecast streams through the http protocol -- it's designed to provide content using the broadcast model instead of pointcast. Apache is a good platform for individual streams.
My car gets 40 rods to the hogshead, and that's the way I likes it!
Streaming an MP3 file out of a CGI works fine, but if you're concerned about bandwidth, you should be sure to rate-limit it: don't send the data much faster than the bitrate of the file.
In addition, I got the apache system to work well enough for my needs (though i need to fitz with LAME to get smaller files -- 44/128s would kill my bitrate quota). the trick was to add the "audio/x-mpegurl m3u" line to the server mime.types file (it isn't there by default).
If you are using someone else's server (you can't change conf info), you can also do it by puting the line "AddType audio/x-mpegurl .m3u" in the .htaccess file for the directory containing the m3us. to minimize constant .htaccess accessing (apache will look it up for every load in that path), you might consider putting all the .m3u files in a single directory by themselves.
Thanks for the pointers...
"But remember, most lynch mobs aren't this nice." (H.Simpson)
-- Joe