|
Greetings, thank you for such a solid work. I am trying to perform the SIMPLE task of calling a phone number and detecting the button that is pressed on the other end. I used the Julmar.ITAPI library at first but couldn't get it to work with events. I switched to the Tapi3Lib, and studied your code. It all works great, i can make the call. However, as soon as I add the Sub that handles the Tapi.Event, everything stops working! I get an error message about InteOp Services. If I take out the sub, everything works fine and I can make the call.
So -> Event Handler Sub, program crashes, Tapi_obj not initalized
-> No event handler sub, program proceeds, tapi_obj is initalized correctly, and call is made.
HELP!
I attached my code below
Imports TAPI3Lib
Public Class frmCallingNow
Private str_buzzer As String
Private call_obj As ITBasicCallControl
Private addr_obj As ITAddress
Private WithEvents tapi_obj As TAPI
Private Const MediaAudio As Integer = 8
Private Const MediaModem As Integer = 16
Private Const MediaFax As Integer = 32
Private Const MediaVideo As Integer = 32768
Private RegCookie As Integer
Public Sub New(ByVal hndlToGodModule As GodModule, ByVal buzzer As String)
.
.
.
'TAPI3 CODE
Try
Dim MediaTypes As Integer
tapi_obj = New TAPI3Lib.TAPI()
tapi_obj.Initialize()
Dim AddressCollection As ITCollection = tapi_obj.Addresses()
For Each Address As ITAddress In AddressCollection
If Address.State = TAPI3Lib.ADDRESS_STATE.AS_INSERVICE Then
Dim mediaSupport As ITMediaSupport = Address 'extract media support interface from the address
MediaTypes = mediaSupport.MediaTypes
mediaSupport = Nothing
If (MediaTypes And MediaModem) = MediaModem Then
'address is data modem
If (MediaTypes And MediaAudio) = MediaAudio Then
'this address is a voice-supporting fax/modem: SELECT THIS ADDRESS
addr_obj = Address
Exit For
End If
End If
End If
Next
If Not (addr_obj Is Nothing) Then 'If we have an address
RegCookie = tapi_obj.RegisterCallNotifications(addr_obj, True, False, MediaTypes, 1) 'Register the notifications for the selected address
'Specify which notifications we are interested in
tapi_obj.EventFilter = (TAPI_EVENT.TE_DIGITEVENT Or TAPI_EVENT.TE_TONEEVENT Or TAPI_EVENT.TE_CALLSTATE)
call_obj = addr_obj.CreateCall(buzzer, TAPI3Lib.TapiConstants.LINEADDRESSTYPE_PHONENUMBER, MediaTypes)
call_obj.Connect(False)
Else
MessageBox.Show("No Address Selected", "TAPI Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch ex As Exception
MessageBox.Show(ex.ToString, "TAPI Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
'TAPI3Lib CODE
' IF I REMOVE THE COMMENTS OFF OF THE FOLLOWING BLOCK, THE APP CRASHES WITH INTEROP EXCEPTION
'Private Sub MY_TAPI_EVENTS(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object) Handles tapi_obj.Event
' Select Case TapiEvent
' Case TAPI3Lib.TAPI_EVENT.TE_DIGITEVENT
' MessageBox.Show("Digit input = " + pEvent.ToString)
' Case TAPI_EVENT.TE_TONEEVENT
' Case TAPI_EVENT.TE_CALLSTATE
' End Select
'End Sub
Private Sub lbl_CallingNowForm_Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl_CallingNowForm_Cancel.Click
If tapi_Obj Is Nothing Then
Me.DialogResult = Windows.Forms.DialogResult.Cancel
Else
tapi_Obj.Dispose()
addr_obj.Dispose()
call_obj.Dispose()
Me.DialogResult = Windows.Forms.DialogResult.Cancel
End If
End Sub
End Class
|
|
|
|
|
Update:::
Ok, I fixed the InterOp Problem.. It seems that I couldn't instantiate a new TAPI object like this
tapi_obj = new TAPI3Lib.TAPIClass
Instead I had to do what is suggested in the article above.
I'm still trying to find which event is raised when a button is pressed on the phone... I'm testing with a Nokia Cell phone, and I'm switching to land line. will keep you guys posted
|
|
|
|
|
Abulfar wrote:
tapi_obj.EventFilter = (TAPI_EVENT.TE_DIGITEVENT Or TAPI_EVENT.TE_TONEEVENT Or TAPI_EVENT.TE_CALLSTATE)
that line should come before you register for call notification in order to receive your events.
"Imagination is more important than knowledge.."
{Albert Einstein}
|
|
|
|
|
Thank you for your reply. I found your suggestion kinda strange because my app registers CALLSTATE events (such as connected and disconnected), but I cannot -for the life of me- detect a digitevent or a toneevent. I did what you so kindly suggested, but it didn't seem to have an effect.
I tried scourging through the net for suggestions and I tried everything i can think of. If anyone has a working app that registers digits or tones PLEASE help!
|
|
|
|
|
did you try adding TAPI_EVENT.TE_GATHERDIGITS to the EventFilter ?
try it and tell me the results
"Imagination is more important than knowledge.."
{Albert Einstein}
|
|
|
|
|
I tried what you suggested, and still no-go.
I'm gonna paste my updated code to give you a better idea, but let me tell you what I did while trying to get this thing working.
- I tried Instantiating a ITLegacyCallMediaControl object by CTyping the ITBasicCallControl. The reason why I did this was to try to access the ITLegacyCallMediaControl::DetectDigits(), my code looked something like this
Dim legacy_obj as ITLegacyCallMediaControl
legacy_obj = CType(call_obj, ITLegacyCallMediaControl) 'This worked, no exceptions.
legacy_obj.DetectDigits(TapiConstants.LINEDIGITMODE_DTMF) ' This threw an Interop exception 'Object is not in any of the in place active states, HRESULT 0x80040010
Man, I tried SO MANY things... it's driving me insane. Pasted below is my code. Please help me, and if you can add me on to msn 'fayezelfar[at]hotmail.com'
With my deepest gratitude.
PS: Masr Um Al Dunia! (If you're egyptian, this'll make you laugh )
'TAPI3 CODE
Try
Dim MediaTypes As Integer
Dim m_tapi As New TAPI3Lib.TAPIClass
m_tapi.Initialize()
tapi_obj = m_tapi
Dim AddressCollection As ITCollection = tapi_obj.Addresses()
For Each Address As ITAddress In AddressCollection
If Address.State = TAPI3Lib.ADDRESS_STATE.AS_INSERVICE Then
Dim mediaSupport As ITMediaSupport = Address 'extract media support interface from the address
MediaTypes = mediaSupport.MediaTypes
mediaSupport = Nothing
If (MediaTypes And MediaModem) = MediaModem Then
'address is data modem
If (MediaTypes And MediaAudio) = MediaAudio Then
'this address is a voice-supporting fax/modem: SELECT THIS ADDRESS
addr_obj = Address
Exit For
End If
End If
End If
Next
If Not (addr_obj Is Nothing) Then 'If we have an address
'Specify which notifications we are interested in
tapi_obj.EventFilter = (TAPI_EVENT.TE_CALLSTATE Or TAPI_EVENT.TE_DIGITEVENT Or TAPI_EVENT.TE_GATHERDIGITS)
RegCookie = tapi_obj.RegisterCallNotifications(addr_obj, True, False, MediaTypes, 1) 'Register the notifications for the selected address
Dim legacy As TAPI3Lib.ITLegacyCallMediaControl
call_obj = addr_obj.CreateCall(buzzer, TAPI3Lib.TapiConstants.LINEADDRESSTYPE_PHONENUMBER, TapiConstants.TAPIMEDIATYPE_DATAMODEM)
call_obj.Connect(False)
Else
MessageBox.Show("No Address Selected", "TAPI Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch ex As Exception
MessageBox.Show(ex.ToString, "TAPI Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Private Sub TAPI_EVT_MGR(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object) Handles tapi_obj.Event
'Making a thread to asynchronously process the events
Dim thread_obj As System.Threading.Thread
Dim thread_obj2 As System.Threading.Thread
Select Case TapiEvent
Case TAPI_EVENT.TE_CALLSTATE
thread_obj = New Threading.Thread(AddressOf CallStateEventRaised)
CallStateObject = CType(pEvent, ITCallStateEvent)
thread_obj.Start()
Case TAPI_EVENT.TE_TONEEVENT
thread_obj2 = New Threading.Thread(AddressOf ToneEventRaised)
ToneEventObject = CType(pEvent, ITToneDetectionEvent)
thread_obj2.Start()
Case TAPI_EVENT.TE_DIGITEVENT
Console.WriteLine("hi")
Case TAPI_EVENT.TE_GATHERDIGITS
Console.WriteLine("gather digits triggered")
End Select
End Sub
|
|
|
|
|
Hi,
This application of yours can display video rite? I want to know what is your setup to make it working? Are you using modem? What kind of devices or equipments that you use?
Thanks
Kent
|
|
|
|
|
it can use and display video thru LAN (H323 VoIP Protocol), but with modem you can only use Audio (In / Out)
"Imagination is more important than knowledge.."
{Albert Einstein}
|
|
|
|
|
It is confirmed that with TAPI 3 application you can't have video conference by using modem.
Thanks for the Info.
Best Regards,
Kent
|
|
|
|
|
hey sir...i want some tutorial on this TAPI.. the project that i selected for final year project is based on TAPI...so can u help me how can u start with this project?? i really need help..
|
|
|
|
|
hello, i am really sorry as i will not be able to directly help you but if you face specific troubles with TAPI please post them and i will try to solve them for you.
"Imagination is more important than knowledge.."
{Albert Einstein}
|
|
|
|
|
Does anyone know why my playback terminal remains nothing after an assignment? Below is my code:
Private Sub OnDial(ByVal sender As Object, ByVal e As EventArgs)
Dim tapi As TTapi = New TTapi()
Dim addr As TAddress = Nothing
Dim CurrCall As TCall
tapi.Initialize()
For Each add As TAddress In tapi.Addresses
If (String.Compare(add.ServiceProviderName, "unimdm.tsp", True) = 0 And add.QueryMediaType(TAPIMEDIATYPES.AUDIO)) Then
addr = add
End If
Next
If addr IsNot Nothing Then
addr.Monitor(TAPIMEDIATYPES.AUDIO)
End If
Dim playbackTerminal As TTerminal
Dim Play_FileName As String = Server.MapPath(".\voices\test.wav")
' Create a call -- this should always succeed
CurrCall = addr.CreateCall("5551213", LINEADDRESSTYPES.PhoneNumber, TAPIMEDIATYPES.DATAMODEM)
If CurrCall IsNot Nothing Then
' Get the playback terminal from the call
Try
'THIS IS WHERE PLAYBACK IS UPDATED
playbackTerminal = CurrCall.RequestTerminal(TTerminal.FilePlaybackTerminal, TAPIMEDIATYPES.AUDIO, JulMar.Tapi3.TERMINAL_DIRECTION.TD_RENDER)
'BUT IT IS STILL NOTHING: Playback=Nothing
If playbackTerminal IsNot Nothing Then
playbackTerminal.MediaPlayList = New String() {Play_FileName}
CurrCall.SelectTerminalOnCall(playbackTerminal)
Else
MsgBox("Failed to retrieve playback terminal.")
CurrCall.Disconnect(JulMar.Tapi3.DISCONNECT_CODE.DC_REJECTED)
End If
Catch ex As TapiException
MsgBox(ex.Message)
End Try
|
|
|
|
|
What type is your modem? Make sure that you use VOICE modem.
>> CurrCall = addr.CreateCall("5551213", LINEADDRESSTYPES.PhoneNumber, TAPIMEDIATYPES.DATAMODEM)
it seems like you trying to create a call on DATAMODEM and run playback terminal as TAPIMEDIATYPES.AUDIO.
If you are trying to play a wav file it is supposes to be a playbackTerminal. But if you record voice, use recordingTerminal.
The initialization for playback would look like
ITBasicCallControl2 bc = (TAPI3Lib.ITBasicCallControl2)activeCall;
filePlayBackTerminal = bc.RequestTerminal(TapiConstants.CLSID_String_FilePlaybackTerminal, TapiConstants.TAPIMEDIATYPE_AUDIO, TERMINAL_DIRECTION.TD_CAPTURE);
|
|
|
|
|
TAddress addr = tapi.Addresses[0] ;
LINEADDRESSTYPES addrType = LINEADDRESSTYPES.PhoneNumber ;
TAPIMEDIATYPES mediaType = TAPIMEDIATYPES.AUDIO;
if (addr.QueryMediaType(TAPIMEDIATYPES.VIDEO))
mediaType |= TAPIMEDIATYPES.VIDEO;
try
{
addr.Open(mediaType);
}
catch (TapiException ex)
{
if (ex.ErrorCode == unchecked((int)0x80040004))
{
try
{
addr.Open(TAPIMEDIATYPES.DATAMODEM);
}
catch
{
toolStripStatusLabel1.Text = ex.Message;
}
}
else
{
toolStripStatusLabel1.Text = ex.Message;
}
}
// Create a call -- this should always succeed
currCall = addr.CreateCall(phoneNumber, addrType, mediaType);
if (currCall != null)
{
// Get the playback terminal from the call
try
{
playbackTerminal = currCall.RequestTerminal(
TTerminal.FilePlaybackTerminal,
TAPIMEDIATYPES.AUDIO, TERMINAL_DIRECTION.TD_CAPTURE );
if (playbackTerminal != null)
{
playbackTerminal.MediaPlayList = new string[] { PLAY_FILENAME };
//string[] names = playbackTerminal.MediaPlayList;
//playbackTerminal.Name;
currCall.SelectTerminalOnCall(playbackTerminal);
}
else
{
MessageBox.Show("Failed to retrieve playback terminal.");
}
}
catch (TapiException ex)
{
MessageBox.Show(ex.Message);
}
try
{
// Connect the call
currCall.Connect(false);
toolStripStatusLabel1.Text = "Placing call...";
}
catch (TapiException ex)
{
//toolStripStatusLabel1.Text = ex.Message;
}
}
this is my code, I am aiming to play a wav file as soon as call is connected but my playbackterminal remains null and I get an error Failed to retrieve playback terminal., I am using a voice modem ZOOM 3095, Please can anybody help me its really urgent for me. The same code if I use while connecting to data modem I can dial a call. please help me around waiting for reply. Thanks !!
|
|
|
|
|
Hi, I'm coding a simple answering machine service for Vista. I'm using Mark Smith's TAPIwrapper (TAPI 3.1) for .NET (in Visual Basic Express Edition 2008). The code looks very much like your example - same basic event handling structure - but with additional code to playback a welcome message when a call is answered and to record the caller's message after the welcome message finishes. Everything works nicely with one exception: when a remote caller hangs up, no event fires and the caller's message just keeps on recording. Eventually (after about a full minute), QWEST detects the line is idle and starts their "If you'd like to make a call, please hang up and dial again..." message. Eventually (after 2 minutes or so) QWEST kills the call and the code then finally gets the DISCONNECTED message and resets for another call. I've found several sources on the web that state this is a known issue with Unimodem drivers and voice modems - i.e. the driver does not detect remote hang-up. Many commercial PC answering machine programs apparently use some kind of line monitoring algorithm to work around the problem. If the line is "silent" for a set period of time, they force a disconnect.
My question: are there TAPI API's or other .NET methods that you know of for detecting a "silent" line. I've searched high and low and found nothing so far.
Thanks,
Clayton Gautier
|
|
|
|
|
Please find my code below. The problem is i need to initialize the bcc (basic call control) and ts (terminal support)
ERROR MESSAGE: OBJECT REFERENCE SET TO INSTANCE OF AN OBJECT.
'CODE STARTS HERE
Sub SendTapi(ByVal WavFileName As String)
Dim bcc As TAPI3Lib.ITBasicCallControl2=Nothing
Dim ts As ITTerminalSupport = Nothing
Dim fpbt As ITTerminal = ts.CreateTerminal
(TAPI3Lib.TapiConstants.CLSID_String_FilePlaybackTerminal,
TAPI3Lib.TapiConstants.TAPIMEDIATYPE_MULTITRACK,
TAPI3Lib.TERMINAL_DIRECTION.TD_BIDIRECTIONAL)
Dim mp As ITMediaPlayback = fpbt
Dim audiofile(1) As Object
audiofile(0) = Server.MapPath(WavFileName)
mp.PlayList = audiofile
bcc.unselectterminaloncall(fpbt)
bcc.selectterminaloncall(fpbt)
Dim mc As ITMediaControl = fpbt
mc.Start()
End Sub
PLEASE HELP.
ATOGWE
|
|
|
|
|
Hello,
i am a newbies in TAPI, and would like to know about setting up hardwares require for phone call(computer to phone call).i can do a IP call, but don't know how to do that. please kindly reply me the way to do that.
Thanks in advances,:->
John
|
|
|
|
|
I make an outgoing call, play a wav msg, and disconnect onFileTerminal(when the wave msg finished),everything is ok until then.then I make another outgoing call onDiscoonect event, to do the same things above, but I got the Ecxeption "No call appearance available." on the line "m_call.Cennect(false)", what does it mean?
|
|
|
|
|
I checked the status of curcall and I got that when the line "curcall.Connect(false)" runs, the status of curcall becomes "CALL_STATE.CS_DISCONNECTED". and that's why it makes that Ecxeption,but why does such a thing happen? why it should become disconnected?
|
|
|
|
|
you are probaply handling the wrong reference to the call object, maybe you are disconnecting the call twice or disconnecting the old call, not the new one.
give it a check.
"Imagination is more important than knowledge.."
{Albert Einstein}
|
|
|
|
|
Hi,
I changed my code so that I shutdown tapi and renew it everytime I want to dial the new number, and now I can dial a list of numbers consecutively, without any problem. Thank you for all your patience and being with me till the end.
|
|
|
|
|
Hi,
My goal is to make a phone call and when the user answers the call I
want to play a message.Now this is my code:
<br />
private TAPI3Lib.TAPIClass m_tapi=null;<br />
<br />
private TAPI3Lib.ITAddress m_address=null;<br />
<br />
private TAPI3Lib.ITBasicCallControl m_call=null;<br />
<br />
ITMediaPlayback pMediaPlayback;<br />
<br />
<br />
private bool SelectTerminal()<br />
<br />
{<br />
<br />
try<br />
<br />
{<br />
<br />
ITTerminal pFileTerm=null;<br />
<br />
ITTerminalSupport pTermSup=null;<br />
<br />
pTermSup=(ITTerminalSupport)m_address;<br />
<br />
pFileTerm=pTermSup.CreateTerminal(TapiConstants.CLSID_String_FilePlaybackTerminal, TapiConstants.TAPIMEDIATYPE_AUDIO,TERMINAL_DIRECTION.TD_CAPTURE);<br />
<br />
if(pFileTerm==null)<br />
<br />
MessageBox.Show("terminal is null");<br />
<br />
pMediaPlayback=null;<br />
<br />
pMediaPlayback=(ITMediaPlayback)pFileTerm;<br />
<br />
object[] s=new object[1]; <br />
s[0]="c:\\2.wav";<br />
<br />
pMediaPlayback.PlayList=s;<br />
<br />
ITCallInfo ci=(ITCallInfo)m_call;<br />
<br />
ITBasicCallControl2 cc2=(ITBasicCallControl2)ci;<br />
<br />
cc2.SelectTerminalOnCall(pFileTerm);<br />
<br />
m_control=(ITMediaControl)pFileTerm;<br />
<br />
}<br />
<br />
catch(Exception ex)<br />
<br />
{<br />
<br />
MessageBox.Show(ex.Message);<br />
<br />
}<br />
<br />
return true;<br />
<br />
}<br />
<br />
<br />
private void OnConnect()<br />
<br />
{<br />
<br />
m_control.Start();<br />
<br />
}<br />
when the call is making,an event of Call_Media happens,that is :
CALL_MEDIA_EVENT.CME_STREAM_FAIL
also I think I must use TD_RENDER for playing the wav sound, but when I use that I get this Exception:
System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
What's wrong with my code? PLZ help, It's urgent...Thx
|
|
|
|
|
maybe its the wave file encoding, try recording it with 8 bit mono @ 11 kHz using windows recorder and tell me if it worked.
"Imagination is more important than knowledge.."
{Albert Einstein}
|
|
|
|
|
Yes, That was the problem, I did it and it worked.Thank you so much...
|
|
|
|
|
Hi,
This is my code:
<br />
<br />
private TAPI3Lib.TAPIClass m_tapi=null;<br />
<br />
private TAPI3Lib.ITAddress m_address=null;<br />
<br />
private TAPI3Lib.ITBasicCallControl m_call=null;<br />
<br />
ITMediaPlayback pMediaPlayback;<br />
<br />
<br />
private bool SelectTerminal()<br />
<br />
{<br />
<br />
try<br />
<br />
{<br />
<br />
ITTerminal pFileTerm=null;<br />
<br />
ITTerminalSupport pTermSup=null;<br />
<br />
pTermSup=(ITTerminalSupport)m_address;<br />
<br />
pFileTerm=pTermSup.CreateTerminal(TapiConstants.CLSID_String_FilePlaybackTerminal, TapiConstants.TAPIMEDIATYPE_AUDIO,TERMINAL_DIRECTION.TD_CAPTURE);<br />
<br />
if(pFileTerm==null)<br />
<br />
MessageBox.Show("terminal is null");<br />
<br />
pMediaPlayback=null;<br />
<br />
pMediaPlayback=(ITMediaPlayback)pFileTerm;<br />
<br />
object[] s=null;<br />
<br />
if(m_strFileName.Length<1)<br />
<br />
s=new string[]{"c:\\2.wav"};<br />
<br />
else<br />
<br />
s=new string[]{m_strFileName};<br />
<br />
pMediaPlayback.PlayList=s; <br />
<br />
ITCallInfo ci=(ITCallInfo)m_call;<br />
<br />
ITBasicCallControl2 cc2=(ITBasicCallControl2)ci; <br />
<br />
cc2.SelectTerminalOnCall(pFileTerm);<br />
<br />
m_control=(ITMediaControl)pFileTerm; <br />
<br />
}<br />
<br />
catch(Exception ex)<br />
<br />
{<br />
<br />
MessageBox.Show(ex.Message);<br />
<br />
}<br />
<br />
return true;<br />
<br />
}<br />
<br />
<br />
private void OnConnect()<br />
<br />
{ <br />
<br />
m_control.Start(); <br />
<br />
}<br />
<br />
<\code><br />
<br />
Why I don't hear anything when I pick up the phone?<br />
<br />
I'm a beginner, can anyone help me on this please? Thx in advance ;)
|
|
|
|
|