Programmable Voice

  1. Home
  2. Docs
  3. Programmable Voice
  4. How do I
  5. Perform Music on Hold

Perform Music on Hold

When creating a telephony app, you will often want to play music to your customers that are on hold. There are several ways to do this.

Use a Separate ‘Music On Hold’ Thread

One of the more efficient ways is to set up a separate thread that continuously plays music to a Voice Resource. When you want to have customers listen to that music, you would then half route them to the Voice Resource that is playing the music. You would then route them to a separate channel resource once the operator becomes available.

You would start this up at application start up:

mohChannel = TelephonyServer.GetVoiceResource()

      break; // When you shutdown the application, you will want to set the stop playing variable to true. You will also want to call mohChannel.Stop()

More Advanced Features

There are more advanced features that you can add. For example, you can randomly pick a wav file to play, or use short music snippets, and update the user with the approximate hold time.

Once you want to begin playing to a customer, you would do the following:

m_ChannelResource.RouteHalf(mohChannel); // The customer can now hear the music

Once complete, you would then need to route the channel resource back together with it’s Voice Resource:


A Few Notes

You may want to add an extra voice resource using this approach, so you don’t run out of voice resources. This link describes how to do this.

Also, the example above is just a code snippet. You will want to add additional error handling using Try / Catch Blocks.

It’s also a great idea to put the Music on Hold thread in it’s own class.

As always, don’t hesitate to contact for additional questions.

Was this article helpful to you? Yes 14 No