How do you combine these two different commands into one script:

$ wget http://mymusic.store.com/musicfoo.mp3
#file gets saved as musicfoo.mp3
$ mplayer musicfoo.mp3

wget attempts to save the file to disk with the file's default name/extension (as on the internet)...in my case mp3 file...mplayer uses this file as argument to play it.

Any idea how i can combine this to one script?

  • I might be wrong, but you -MIGHT- be able to just mplayer the URL and have it play the track. I haven't used mplayer in a while, though.
    – Rob
    Nov 22, 2013 at 19:56

4 Answers 4


Play file directly

You do not have to even download these files prior to playing them with mplayer. From the mplayer man page:


  mplayer [options] [file|URL|playlist|-]

So mplayer can play URLs directly.


$ mplayer http://mymusic.store.com/musicfoo.mp3


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.


$ 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.


$ 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
  • Yes, however, it doesn't play as a continuous stream.
    – deostroll
    Nov 23, 2013 at 5:56
  • @deostroll - can you explain your comment, I don't understand what you mean by a continuous stream.
    – slm
    Nov 23, 2013 at 5:58
  • downloading happens...when it exceeds a cache limit it starts playing...meanwhile the downloading of the file continues. So it plays until the cache exhausts...then it waits for the cache to fill up...and so on. So I hear a log of intermittent pauses.
    – deostroll
    Nov 23, 2013 at 6:21
  • @deostroll - see updates, you'll need to play with the cache switches, this is the drawback to playing back in realtime. You're inability to playback directly is a function of your low bandwidth or the limited bandwidth from the server.
    – slm
    Nov 23, 2013 at 7:15
  • @deostroll - I've added 2 additional methods, let me know if you need additional guidance.
    – slm
    Nov 23, 2013 at 9:37


wget http://mymusic.store.com/musicfoo.mp3 && mplayer musicfoo.mp3

The && means "once the left side command has successfully completed". This assumes the left side command does not fork or use non-standard exit status values. I doubt wget does the latter, and as long as you don't use the -b switch, it shouldn't do the former either.

  • No. The argument to mplayer must be the file wget "creates" while downloading...so technically I don't know the argument to mplayer...hope you get my point...
    – deostroll
    Nov 22, 2013 at 20:58
  • If you invoke wget literally as above, the file will be musicfoo.mp3.
    – goldilocks
    Nov 22, 2013 at 21:23
  • I'd want to pass the argument to wget programmatically...hence there is no way for me to determine the name of the file that is going to be downloaded...
    – deostroll
    Nov 23, 2013 at 5:54
  • Why didn't you explain this in your question in the first place and post the code you are actually using, instead of something that you don't really want to do? Anyway, slm may have you covered.
    – goldilocks
    Nov 23, 2013 at 15:37

Try this :

mkdir /tmp/download_$$
cd /tmp/download_$$
wget http://mymusic.store.com/musicfoo.mp3
mplayer *

I have a solution:

fpath=$(basename "$1")
wget $1
mplayer $fpath

The issue with above is that wget will assign a file name for the downloaded file (appending a .1 to its end) if the file name already exists. Hence the value of fpath isn't the correct file so to speak.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .