Monday, March 06, 2006

I got an email question today asking about how to write a .WAV file out to an active call using our TAPI3 wrapper.  It's actually pretty easy to do and it follows along with the normal SDK method used in C++.  Here's the relevant code (for the full example, download the http://www.julmar.com/samples/tapi3wrapper.zip and look at the AutoAttendant sample).

First, when a new offering call shows up, get hold of the file playback terminal for it and set it up to play your .WAV files.  We cannot play the files until the call is answered, but this will essentially "queue" it up.

// Method called when TE_CALLSTATE == OFFERING raised
private void AnswerCall()
{
   // Get the playback terminal from the call
   try
   {
      playbackTerminal = activeCall.RequestTerminal(TTerminal.FilePlaybackTerminal, 
                  TAPIMEDIATYPES.AUDIO, TERMINAL_DIRECTION.TD_CAPTURE);
      if (playbackTerminal != null)
      {
         playbackTerminal.MediaPlayList = new string[] { "Hello.wav" };
         activeCall.SelectTerminalOnCall(playbackTerminal);
         activeCall.Answer();
      }
      else
      {
         MessageBox.Show("Failed to retrieve playback terminal.");
         activeCall.Disconnect(DISCONNECT_CODE.DC_REJECTED);
      }
   }
   catch (TapiException ex)
   {
   }
}

Next, watch for the call media to change indicating we have an active stream for our terminal.  When that happens, start the playback stream:

// Method called when TE_CALLMEDIA is raised
private void OnCallMedia(object sender, TapiCallMediaEventArgs e)
{
   try 
   {
      if (activeCall != null && e.Event == CALL_MEDIA_EVENT.CME_STREAM_ACTIVE &&
            e.Terminal.Direction == TERMINAL_DIRECTION.TD_CAPTURE &&
            playbackTerminal != null)
      {
         playbackTerminal.Start();
         SetStatusMessage("File Playback Terminal started ");
      }
   }
   catch (TapiException ex)
   {
   }
}

Finally, when the file terminal is finished, close and dispose the stream.  This is done just to cleanup the resources properly:

// Method called when TE_FILETERMINAL is raised
private
void OnFileTerminal(object sender, TapiFileTerminalEventArgs e)
{
   // We are interested in TMS_IDLE because we will un-select playback and 
   // select recording
   if (e.State == TERMINAL_MEDIA_STATE.TMS_IDLE)
   {
      if (e.Terminal.Direction == TERMINAL_DIRECTION.TD_CAPTURE && playbackTerminal != null)
      {
         try
         {
            // Remove the playback terminal
            activeCall.UnselectTerminalOnCall(playbackTerminal);
            playbackTerminal.Dispose();
            playbackTerminal = null;
         }
         catch (TapiException ex)
         {
         }
      }
   }
}

That's pretty much it -- there's a full sample of this that should work with voice modems or any streaming-capable TSP. 

Updated: 3/16/05 -- It doesn't appear to completely work with the H.323 provider; the file terminal gets connected but apparently never reports an IDLE state and so never gets disconnected in the above sample.  This appears to be true of the Platform SDK samples as well.

posted on 3/6/2006 5:02:34 PM (Central Standard Time, UTC-06:00)  #   

Related Posts:
Implementing Drag/Drop with TabControl
ATAPI assembly updated!
Creating Extensible Applications with MAF (System.AddIn)
Guerrilla .NET Tampa samples
TSP++ 3.0 is now free!
Adding Pause/Resume into SynchronizationContext based components

Tracked by:
"buy cipro" (online) [Trackback]
"buy bupropion" (online) [Trackback]
"45 diet tip" (online) [Trackback]
"canada debt free" (on line) [Trackback]
"phentermine pill" (on line) [Trackback]
"robots lowest cheap airfares" (air online) [Trackback]
"bonus casino gambling" (casino online) [Trackback]
"y37bl" (y37bl) [Trackback]
"4tsq8" (4tsq8) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"nk4ye" (nk4ye) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"1k8jd" (1k8jd) [Trackback]
"Welcome to linuxtld.com!" (Welcome to linuxtld.com!) [Trackback]
"nyav.purple-icing.com" (nyav.purple-icing.com) [Trackback]
"oqxtu" (oqxtu) [Trackback]
http://www.walshperformancegroup.com/contact.htm [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"Welcome to linuxtld.com!" (Welcome to linuxtld.com!) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"search the web" (search the web) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"meskateboards.com/mesite01.swf" (meskateboards.com/mesite01.swf) [Trackback]
"o7w34" (o7w34) [Trackback]
"purple-icing.com" (purple-icing.com) [Trackback]
"d4gug" (d4gug) [Trackback]
"vkaed" (vkaed) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"fp8ll" (fp8ll) [Trackback]
"default parking homes for sale at free815.com" (default parking homes for sale ... [Trackback]
"free815.com" (free815.com) [Trackback]
"ue6ax" (ue6ax) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"kodak camers" (kodak camers) [Trackback]
"cellphone pictures" (cellphone pictures) [Trackback]
"unicorn tattoo" (unicorn tattoo) [Trackback]
"ecstacy pills" (ecstacy pills) [Trackback]
"lake shafer boat rentals indiana" (lake shafer boat rentals indiana) [Trackback]
"active mixer device%2C computer volume" (active mixer device%2C computer volume... [Trackback]
"local rap artist richmond virginia" (local rap artist richmond virginia) [Trackback]
"very very ugly girls" (very very ugly girls) [Trackback]
"worldur a dirty fucking sleezy cunt" (worldur a dirty fucking sleezy cunt) [Trackback]
"cesti regalo" (cesti regalo) [Trackback]
"teen dorm fuck" (teen dorm fuck) [Trackback]
"girls tight pizza" (girls tight pizza) [Trackback]
"vergognoso ragazze sex" (vergognoso ragazze sex) [Trackback]
"painful gay anal" (painful gay anal) [Trackback]
"porn name generator" (porn name generator) [Trackback]
"help desk it software" (help desk it software) [Trackback]
"accident attorney" (accident attorney) [Trackback]
"nipple toys" (nipple toys) [Trackback]
"toronto real estate sale" (toronto real estate sale) [Trackback]