⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 the autoanswerobserver.java file.txt

📁 Creating the Auto Answering Machine Application
💻 TXT
字号:
/*Import required JTAPI classes*/
import javax.telephony.*;
import javax.telephony.events.*;
import javax.telephony.media.*;
import javax.telephony.media.events.*;
import java.net.*;
/* 
This class provides the media call observer for the Auto Reply Application.
Class:AutoAnswerObserver-Class to detect the call made by caller
Methods:
setJtapiVariables():This method is used to initialize the terminal connection objects.
*/
public class AutoAnswerObserver implements MediaCallObserver,Runnable
{
   boolean isAnswering = false;
   AutoAnswerGUI replyApp = null;
   Call phoneCall = null;
   private Connection connections[] = null;
   private TerminalConnection tconnection = null;
   private TerminalConnection  desttconnection =  null;
   Thread t=null;
   AnswerText st=null;
   /*
   Public constructor takes the object of AutoAnswerGUI class as parameter.
   AutoAnswerObserver():
   Parameters:
   replyApp:object of AutoAnswerGUI
   Return Type:NA
   */
   public AutoAnswerObserver(AutoAnswerGUI replyApp)
   {
      this.replyApp = replyApp;
   }
   /* 
   This method is used to initialize the terminal connection objects.
   Parameters:Object of Call class
   Return Value:void
   */
   private void setJtapiVariables(Call c)
   {
   phoneCall = c;
   try
   {
      connections = c.getConnections();
      TerminalConnection[] tc;
      phoneCall.addObserver(this);
      tc = connections[0].getTerminalConnections();
      tconnection = tc[0];
      Terminal terminal = tconnection.getTerminal();
      terminal.addCallObserver(this);
      /*
      Creating the remote terminal connection. The remote connection is the origination connection
      which is always the first connection in the connections array.
      */
      tc = connections[1].getTerminalConnections();
      desttconnection = tc[0];
   }
   catch(Exception e)
   {
      System.out.println("Exception occurred in setJtapiVariables(): " + e.toString());
   }
}    
/* 
The callChangedEvent() method is called every time an event associated with the phone call is
raised.
Parameters:Array of CallEv class eventList
Return Type:void
*/
public void callChangedEvent(CallEv[] eventList)
{
   if(phoneCall == null)
   {
      setJtapiVariables(eventList[0].getCall());
   }
   for (int i = 0; i <eventList.length;  i++)
   {
      CallEv ev = eventList[i];
      TerminalConnection terminalConnection = ((TermConnEv)ev).getTerminalConnection();
      MediaTerminalConnection mtc = (MediaTerminalConnection)terminalConnection;
      switch(ev.getID())
      {
         case TermConnCreatedEv.ID:
         try
         {
            /* 
            Specifying the audio file that is to be played when terminal connection is created.
            */
            System.out.println("Connection Created.");
            mtc.useDefaultSpeaker();
            mtc.useDefaultMicrophone();
            mtc.useP layURL(new URL("file:helloworld.wav"));
            isAnswering = false;
         }
         catch (Exception excp)
         {
            System.out.println("Exception TermConnCreatedEv:" + excp.toString());
         }
         break;
         case TermConnRingingEv.ID:
         try
         {
            System.out.println("Ringing");
            if(isAnswering == false)
            {
               /*Answering the phone call.*/
               isAnswering = true;
               terminalConnection.answer();
               t=new Thread(this,"Node action");
               t.start();
            }
         }
         catch (Exception excp)
         {
            System.out.println("Exception occurred while answering the phone call:" +
            excp.toString());
         }
         break;
         case MediaTermConnAvailableEv.ID:
         try
         {
            System.out.println("Media Term Connection Available event.");
            mtc.startPlaying();
         }
         catch (Exception excp)
         {
            System.out.println("Exception occurred in startPlaying():" + excp.toString());
         }
         break;
         case MediaTermConnStateEv.ID:
         try
         {
            /*Check if playing is done.*/
            int state = mtc.getMediaState();
            System.out.println("Playing"+state);
            state = state &MediaTerminalConnection.PLAYING;
            System.out.println("Playing"+state);
            if(state == 0)
            {
               /*
               Stop playing and closing the phone connection.
               */
               mtc.stopPlaying();
               hangupConnection();
            }
         }
         catch (Exception excp)
         {
            System.out.println("Exception occurred in stopPlaying():" + excp.toString());
         }
         break;
         case MediaTermConnUnavailableEv.ID:
         try
         {
            /* 
            Specifying that the Media Terminal Connection is not available.
            */
            System.out.println("Media terminal connection is not available.");
            mtc.stopPlaying();
         }
         catch(Exception e)
         {
            System.out.println("Exception occurred in MediaTermConnUnavailableEv.ID:" +
            e.toString());
         }
         /*
         Closing the telephone connection.
         */
         hangupConnection();
         break;
         default:
         break;
         }
      }
   }
   /*
   Run method to speak the answer
   Parameters:NA
   Return Value:Void
   */ 
   public void run()
   {
   /*
      Initialize a new object of AnswerText class
      */
      st=new AnswerText("Thank You for calling me i would be glad to say hello", "kevin16");
      /*
      Invoke the answerSelText() method of AnswerText class
      */
      st.answerSelText(this);
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -