Asterisk cmd MusicOnHold


Play Music On Hold indefinitely.



Plays hold music specified by class. If omitted, the default music source for the channel will be used. If you have configured MusicOnHold in musiconhold.conf it will get played automatically if the extension is put on hold. This command FORCES musiconhold music.

The default MusicOnHold class is set with the SetMusicOnHold command (Deprecated in 1.6).


Extension defined in extensions.conf with "forced" MusicOnHold. Remember to Answer before letting the music pour down the line. Otherwise music on hold will not work correctly.
; Answer required as Music On Hold does not answer the call
exten => 6000,1,Answer
exten => 6000,2,MusicOnHold()

It is often useful to turn off music on hold in several situations:
  1. when a particular extension calls (originates)
  2. when connectiong to a particular extension
  3. when traversing a particularly expensive network
  4. when connecting to a conference

(So, how do we do handle each situation?)

You can turn off MOH on a per call by using the SetMusicOnHold command (Deprecated in 1.6).

Add a new class to musiconhold.conf

Create a macro in extensions.conf to turn off MOH
exten => s,1,NoOp(Turn off MOH for this channel)
exten => s,2,SetMusicOnHold(none)

Now call this macro when you dial an extension
exten => 7020,1,NoOp(Dial -> IAX2/outbound/${EXTEN})
exten => 7020,n,Dial(IAX2/outbound/${EXTEN},,M(nomusic))
exten => 7020,n,Hangup

Asterisk 1.6

Plays hold music specified by class. If class is omitted, the default music source for the channel will be used. Change the default class with Set(CHANNEL(musicclass)=...). If duration is given, hold music will be played specified number of seconds. If duration is ommited, music plays indefinitely.

Returns 0 when done, -1 on hangup.

play-fifo (3rd party addition)

This small C program will create if necessary, open and listen on a fifo for slinear audio and delivers it to STDOUT. If STDOUT is blocking, it discards the data. The idea is that you would use it in a custom class in res_musiconhold. Now you can use whatever means you choose in a seperate process to deliver raw 8khz mono slin to the fifo which will be heard as the music class fifo. An example would be to play your line-in into the fifo and the buffer will not overflow because this program does a poll on the STDOUT and discards STDIN when STDOUT is busy.
You can find it here, it is not part of the Asterisk distribution.

See also

Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

Created by: oej, Last modification: Fri 03 of Jun, 2016 (15:49 UTC) by elano
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+