Upgrade 3CX to v18 and get it hosted free!

Asterisk cmd SetMusicOnHold

Author image

Synopsis:

Set default Music On Hold class

Description:

SetMusicOnHold(class)

Sets the default class for music on hold for a given channel. When music on hold is activated, this class will be used to select which music is played.

NOTE: This sets what music the perticular channel will hear. Example:

  • Channel A calls extension for channel B
  • The dialplan executes SetMusicOnHold(music_A)
  • The dialplan Dials channel B, channel B answers and the call is bridged.
  • Channel B puts channel A on hold: channel A hears “music_A” hold music.
  • Channel A puts channel B on hold: channel B hears default hold music (which may or may not be “default” depending on your musiconhold.conf and channel conf file settings).

To set the music on hold for the channel that is being dialed, you must use the M (macro) flag from the Dial command.

[context_A]
exten=B,1,SetMusicOnHold(music_B) ; channel A is the active channel, so make it hear music_B
exten=B,1,Dial(SIP/channel_B,M(setmusiconhold,music_A))
exten=C,1,SetMusicOnHold(music_C)
exten=C,1,Dial(SIP/channel_C,M(setmusiconhold,music_A))

[context_B]
exten=A,1,SetMusicOnHold(music_A)
exten=A,1,Dial(SIP/channel_A,M(setmusiconhold,music_B))
exten=C,1,SetMusicOnHold(music_C)
exten=C,1,Dial(SIP/channel_C,M(setmusiconhold,music_B))

[context_C]
exten=B,1,SetMusicOnHold(music_B)
exten=B,1,Dial(SIP/channel_B,M(setmusiconhold,music_C))
exten=C,1,SetMusicOnHold(music_C)
exten=C,1,Dial(SIP/channel_C,M(setmusiconhold,music_C))

[macro-setmusiconhold]
exten=s,1,SetMusicOnHold(${ARG1}) ; channel B is the active channel, so make is hear music_A
exten=s,2,Set(MACRO_RESULT=)

This may seem backwards, however, if you remember that SetMusicOnHold sets the music that the active channel will hear, and not the music that it will play, that should help alleviate any confusion. In the example above, you want channel A to hear the music of channel B (music_B) and you want channel B to hear channel A’s music (music A). So, when channel A puts channel B on hold, channel B hears channel A’s hold music.

New in Asterisk 1.6

SetMusicOnHold is now deprecated. You should use Set(CHANNEL(musicclass)=…) instead.

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.