Synopsis
Play Music On Hold indefinitely.
Description
MusicOnHold([class])
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).
Example
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:
- when a particular extension calls (originates)
- when connectiong to a particular extension
- when traversing a particularly expensive network
- 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
[none]
mode=files
directory=/dev/null
Create a macro in extensions.conf to turn off MOH
[macro-nomusic]
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
MusicOnHold(class[,duration])
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