Upgrade 3CX to v18 and get it hosted free!

Asterisk cmd MusicOnHold

Author image

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:

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

See also


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


Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.