Java dtmf

Contenu du snippet

Code source issu de sun pour décoder du DTMF

Source / Exemple :


class DtmfCallObserver implements  MediaCallObserver {

  /*

  • This CallObserver will be notified of Call events. We want to first
  • answer the incoming telephone call, and then perform the neccessary
  • media actions to perform DTMF.
  • /
public void callChangedEvent(CallEv evlist[]) { for (int i = 0; i < evlist.length; i++) { CallEv ev = evlist[i]; if (ev instanceof TermConnRingingEv) { /* Answer the phone. */ TerminalConnection tc = ((TermConnEv)ev).getTerminalConnection(); try { tc.answer(); } catch (Exception excp) { // Handle Exceptions } } else if (ev instanceof MediaTermConnAvailableEv) { /* We want to start DTMF-detection TerminalConnection tc = (TermConnEv)ev.getTerminalConnection(); MediaTerminalConnection mtc = (MediaTerminalConnection)tc; try { mtc.setDtmfDetection(true); } catch (Exception excp) { // Handle exceptions } } else if (ev instanceof MediaTermConnUnavailableEv) { /* Turn off DTMF-detection */ TerminalConnection tc = (TermConnEv)ev.getTerminalConnection(); MediaTerminalConnection mtc = (MediaTerminalConnection)tc; try { mtc.setDtmfDetection(false); } catch (Exception excp) { // Handle exceptions } } else if (ev instanceof MediaTermConnDtmfEv) { /* Print out the DTMF digits */ char digit = ((MediaTermConnDtmfEv)ev).getDigit(); System.out.println("detected DTMF: " + digit); } } } } public class DtmfCall { public static final void main(String args[]) { /*
  • Create a provider by first obtaining the default implementation of
  • JTAPI and then the default provider of that implementation.
  • /
Provider myprovider = null; try { JtapiPeer peer = JtapiPeerFactory.getJtapiPeer(null); myprovider = peer.getProvider(null); } catch (Exception excp) { System.out.println("Can't get Provider: " + excp.toString()); System.exit(0); } /*
  • Locate the Terminal associated with our near end and place a call
  • observer on it. This will instruct the implementation to add a call
  • observer once a telephone call comes to the Terminal. We are assuming
  • Terminals are named after a primary telephone number on that terminal.
  • /
Terminal terminal; try { terminal = myprovider.getTerminal("4761111"); terminal.addCallObserver(new MachineCallObserver()); } catch (Exception excp) { // Handle all Exceptions } } }

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.