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?
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!>

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,


Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

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


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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.