Music on Hold sort order - is there a way?


Install - AsteriskNOW 1.5.0
Asterisk -
FreePBX -
Fully updated as of 13.02.2011

I’ve been trying to work out how to sort the MOH once its uploaded. I came across this post from 2006: but nothing appears to have been resolved regarding this issue.

It seems strange that you can label your MOH files as 01moh.wav, 02moh.wav, 03moh.wav etc… but when they’re uploaded they appear in a different sort order. What makes this even more strange is that there is an option to play them randomly, which would suggest that the opposite of random was sorted, and yet I can find no way to do this.

Incidentally, I can’t achieve a sort order using AsteriskNOW 1.7.1 with Asterisk 1.6 either.

Any ideas?



This is from the documentation of Asterisk musiconhold:

Files are played in normal sorting order (same as a sorted directory listing)

If you set one if these options you can get some sort of sorting:

sort=random    ; Sort the files in random order
sort=alpha     ; Sort the files in alphabetical order.  If this option is
               ; not specified, the sort order is undefined.

Hi Mikael

Thank you for the quick response.

Where do I set the options you mention? Is it done through the FreePBX GUI or the CMD Line?

Kind regards


Unfortunately, you can’t do from FreePBX, you can try by adding the setting to musiconhold_additional.conf under one of your categories. Then you do a module reload in Asterisk CLI. Now try your Music on Hold and see if you get the desired result.

If you feel like it, please file a new ticket in the ticket system, setting it to a Feature Request, about these settings.

In Elastix, the files are actually sorted by FILE NAME LENGTH. Yes, that’s right. Just name the first file something like 01.wav, the next one 001.wav, and the next one 0001.wav, and you are good to go.

Putting sort = Alpha had no effect at all in musiconhold_custom.conf or musiconhold_additional.conf. But once I uploaded the 1st file with a shorter name, presto!

Just thought I’d share this with anyone hitting their head against the brick wall.

Suthern, could you help me? I am running Elastix 1.6-12 and I can’t get the MOH sorted. I have posted my question over at Elastix’s forum but haven’t gotten any replies yet. I am not sure what I am doing wrong.

This is the posting over at Elastix:
This seems like a easy task but I can’t get Elastix to play my 8 MOH files (1.wav, 2.wav, …8.wav) in ascending order. I tried using sort=alpha but still Asterisk play in some crazy order. Even the display of the files under the web interface is not correct.

I also tried the suggestions from this link (including the file name length) but it did not work for me:

I am running Elastix 1.6-12. Help please!

The way I got them to play in order (if I remember correctly) is by the number of digits in the file name!

Sounds strange, but give it a shot. Name them like:
50000.wav …etc

It matters not what the actual number is.

You could even do something like:
xxxxx.wav …etc

Would you mind confirming if that works for you?

OK, I got it working but under Elastix 2.0 not 1.6. Maybe there was a bug in the version.

FYI, I do need to add “sort=alpha” into the config file to make it work. I tried adding it to musiconhold_custom.conf but it didn’t sort correct.

This is my musiconhold_additional.conf

This doesn’t seem to work for me in FreePBX 2.9. Changing the sort to alpha in the conf file seems to get ignored. Wondering if anybody has it working in 2.9!