How to play audio files in Asterisk directly from a URL?

Hello there,

Is there any way to play audio files in Asterisk directly from a URL?  Ideally, I'd send the URL to Asterisk as an argument to an AGI script and then play the audio directly, without having to copy the file to the Asterisk server.

If possible, would anyone send me examples of how this could be done?

Thanks in advance,

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ron MalmsteadInformation Services ManagerCommented:
Unless you are using a streaming source, the file will have to be copied somehow.

You can use streaming sources with asterisk, like shoutcast, or your own mms server (windows media mms on win2k3 for example).

Look at this wiki page.
It's documents up to version 1.4, but I suspect it hasnt' changed all that much.

The example from wiki page that applies to a file source.

#/usr/bin/wget -q -O - | /usr/local/bin/madplay -Q -z -o raw:- --mono -R 8000 -a -12 -

Doing it that way will begin a new download of the file every time it's played.
Using the streaming method, will connect to a live stream which plays in a loop.
if -n "`ls /tmp/mayakpipe`" ; then
     rm /tmp/mayakpipe
mkfifo $PIPE
cat $PIPE &
sleep 3
mplayer -cache 8192 -cache-min 4 mms:// -really-quiet -quiet -ao pcm:fast -af resample=8000,channels=1,format=mulaw -ao pcm:file=$PIPE
rm $PIPE
leoburdAuthor Commented:
Dear xuserx2000,

I really liked your proposal and will try it soon.

One question.  Would your solution only work with MOH?  Have you ever tried the MP3Player command (

Thanks so much for all your help,


Ron MalmsteadInformation Services ManagerCommented:
That solution, is only for MOH.

I haven't tested the mp3 player command, but I found this on wiki.
There is an "alternative" approach listed lower on the page, which you might want to test out.
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

leoburdAuthor Commented:
Thanks once again, xuserx2000!

Sorry for taking so long to get back to you.  I'm still in the process of testing your proposed solution(s).


Hello Leoburd,

I actually recently finished a very similar project. I created a webpage (php) that displays a list of sound files (wav and gsm) in a directory. When you click on one of these files, it connects to asterisk, to make an ORIGINATE call, and then PLAYBACK the file that had been clicked on. Note that the sound files and the HTTPd are located on the same machine. Is that similar to what you are trying to achieve ?

leoburdAuthor Commented:
Hello N,

Your project sounds really interesting!  However, I'm still looking for a way to play remote audio files in Asterisk.  Would your solution work for remote files?


Here are the different ways I'd approach your project:

1) Replicate the audio files onto the asterisk server through a synchronization script. Then purge the audio files you don't need anymore.

2) Run an httpd daemon on both the asterisk server, and the remote server containing the files. Run a PHP script on the asterisk server that queries the remote server through HTTP for the list of files, and when one is selected, the file gets downloaded (using fsockopen on port 80), then connect to Asterisk Manager to request a phone to ring and listen to the audio file, and delete it once it has been played.

3) Start from the server that has the files. Use a PHP script to show the available audio files, and once one is selected, the file is pushed (ftp for ex) to the asterisk server, where a dedicated dialplan can parse it and play it.

4) If the OS permits, run Asterisk on the server that contains the audio file. <grin!>


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leoburdAuthor Commented:
Based on the multiple responses that I got, there does not seem to exist a simple solution to the problem I'm trying to solve.  

One way or another, it seems that the best approach would involve copying the audio file to the Asterisk server before playing it.  The MP3Player command might do the trick, but it's hard to tell how reliable it is.

xuserx2000 provided the most complete response.  That's why I'm granting him/her the points.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
IP Telephony

From novice to tech pro — start learning today.