Play file directly
You do not have to even download these files prior to playing them with mplayer
. From the mplayer
man page:
excerpt
mplayer [options] [file|URL|playlist|-]
So mplayer can play URLs directly.
Example
$ mplayer http://mymusic.store.com/musicfoo.mp3
Performance
You'll likely need to adjust the cache values to get mplayer
to playback your content smoothly. There are a few switches to mplayer
that allows for this.
excerpt from mplayer man page
-cache <kBytes>
This option specifies how much memory (in kBytes) to use
when precaching a file or URL. Especially useful on slow media.
-cache-min <percentage>
Playback will start when the cache has been filled up to
<percentage> of the total.
So perhaps something like this, you'll to play with these values to get smooth playbacks for your situation.
$ mplayer -cache 8000 -cache-min 30 http://mymusic.store.com/musicfoo.mp3
Download and play
Another method discussed in some of the other answers is to use wget
to download and then play the file. The inherent problem with this approach is getting the file name to play, after the file is done downloading it.
curl piped to mplayer
With this approach there are actually 2 techniques within it. The first is to use wget
or curl
to start the download and then pipe the data to mplayer
.
Example
$ wget http://mymusic.store.com/musicfoo.mp3 -O - | mplayer -
You can also cache the download here as before:
$ wget http://mymusic.store.com/musicfoo.mp3 -O - | mplayer -cache 8192 -
curl 1st, then mplayer
The other method is to download the file and then play it. You could use a Bash function to wrap this since it now becomes a 2 step process where the file is completely downloaded first, and then played afterwards.
Example
$ function smplayer() { wget $@ && mplayer $(basename $@); }
Then to do a download and play you'd run the function like so:
$ smplayer http://mymusic.store.com/musicfoo.mp3