@ -28,7 +28,8 @@
* @author Lyubomir Marinov
* /
public class DTMFHandler
implements KeyEventDispatcher
implements KeyEventDispatcher ,
Runnable
{
/ * *
* The < tt > Logger < / tt > used by the < tt > DTMFHandler < / tt > class and its
@ -64,6 +65,17 @@ public class DTMFHandler
* /
public static final String DTMF_TONE_PREFIX = "DTMFTone." ;
/ * *
* The list of audio DTMF tones to play .
* /
private Vector < DTMFToneInfo > dmtfToneNotifications
= new Vector < DTMFToneInfo > ( 1 , 1 ) ;
/ * *
* The thread which plays the audio DTMF notifications .
* /
private Thread dtmfToneNotificationThread ;
/ * *
* All available tones and its properties like images for buttons , and
* sounds to be played during send .
@ -411,8 +423,19 @@ private synchronized void startSendingDtmfTone(DTMFToneInfo info)
{
if ( info . sound ! = null )
{
currentlyPlayingTone = GuiActivator . getNotificationService ( )
. fireNotification ( DTMF_TONE_PREFIX + info . tone . getValue ( ) ) ;
synchronized ( dmtfToneNotifications )
{
boolean startThread = ( dmtfToneNotifications . size ( ) = = 0 ) ;
dmtfToneNotifications . add ( info ) ;
if ( startThread )
{
dtmfToneNotificationThread
= new Thread (
this ,
"DTMFHandler: DTMF tone notification player" ) ;
dtmfToneNotificationThread . start ( ) ;
}
}
}
if ( callContainer ! = null )
@ -477,10 +500,6 @@ private void startSendingDtmfTone(Call call, DTMFToneInfo info)
* /
public synchronized void stopSendingDtmfTone ( )
{
if ( currentlyPlayingTone ! = null )
GuiActivator . getNotificationService ( )
. stopNotification ( currentlyPlayingTone ) ;
if ( callContainer ! = null )
{
stopSendingDtmfTone (
@ -591,4 +610,39 @@ public DTMFToneInfo(
this . sound = sound ;
}
}
/ * *
* Runnable used to read all waiting DTMF tone notification .
* /
public void run ( )
{
boolean moreToPlay = ( dmtfToneNotifications . size ( ) > 0 ) ;
DTMFToneInfo toneToPlay = null ;
while ( moreToPlay )
{
toneToPlay = dmtfToneNotifications . get ( 0 ) ;
if ( toneToPlay . sound ! = null )
{
// Plays the next DTMF sond notification.
currentlyPlayingTone
= GuiActivator . getNotificationService ( ) . fireNotification (
DTMF_TONE_PREFIX + toneToPlay . tone . getValue ( ) ) ;
// Waits for the current notification to end.
while ( GuiActivator . getNotificationService ( )
. isPlayingNotification ( currentlyPlayingTone ) )
{
Thread . yield ( ) ;
}
// Removes the ended notification from the DTMF list.
GuiActivator . getNotificationService ( )
. stopNotification ( currentlyPlayingTone ) ;
synchronized ( dmtfToneNotifications )
{
dmtfToneNotifications . remove ( 0 ) ;
moreToPlay = ( dmtfToneNotifications . size ( ) > 0 ) ;
}
}
}
}
}