How do I perform Music On Hold?

From VESupport

Jump to: navigation, search

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. We will discuss a few good options.

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. Here's an example of how to do this:


This is how you would start the music on hold thread. You could start this up at application start up:

mohChannel = TelephonyServer.GetVoiceResource()

while(true)
{
   mohChannel.Play("moh.wav");
   if(stopPlaying)
   {
      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()
   }
}

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:

m_ChannelResource.RouteFull(m_VoiceResource);

A few notes: You may want to add an extra voice resource using this approach, that way you don't run out of voice resources. This link describes how to do this: How do I add additional Voice Resources?

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 support@inventivelabs.com for additional questions.

Use the Voice Resource from the Channel Resource of the Customer

To be added.

Personal tools