diff options
author | Damian Minkov <damencho@jitsi.org> | 2012-11-06 11:06:00 +0000 |
---|---|---|
committer | Damian Minkov <damencho@jitsi.org> | 2012-11-06 11:06:00 +0000 |
commit | f65dc96da2a8f3095135af63f9fa8f973019ab4d (patch) | |
tree | 2c3fd50b734b6b726acf6274178aa90fc9038ad7 /src/net/java | |
parent | a86e412e2eb335ff5fc39ad0646c673be5d29c09 (diff) | |
download | jitsi-f65dc96da2a8f3095135af63f9fa8f973019ab4d.zip jitsi-f65dc96da2a8f3095135af63f9fa8f973019ab4d.tar.gz jitsi-f65dc96da2a8f3095135af63f9fa8f973019ab4d.tar.bz2 |
Synchronize list of currently playing clips in SoundNotificationHandler.
Diffstat (limited to 'src/net/java')
-rw-r--r-- | src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java b/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java index adb789a..b12d7de 100644 --- a/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java +++ b/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java @@ -6,7 +6,6 @@ */ package net.java.sip.communicator.impl.notification; -import java.awt.*; import java.util.*; import java.util.concurrent.*; @@ -25,6 +24,12 @@ public class SoundNotificationHandlerImpl implements SoundNotificationHandler { /** + * The logger that will be used to log messages. + */ + private Logger logger + = Logger.getLogger(SoundNotificationHandlerImpl.class); + + /** * The indicator which determines whether this * <tt>SoundNotificationHandler</tt> is currently muted i.e. the sounds are * off. @@ -105,7 +110,10 @@ public class SoundNotificationHandlerImpl if(audio == null) return; - playedClips.put(audio, data); + synchronized(playedClips) + { + playedClips.put(audio, data); + } boolean played = false; @@ -123,15 +131,18 @@ public class SoundNotificationHandlerImpl } finally { - if (!played) - playedClips.remove(audio); + synchronized(playedClips) + { + if (!played) + playedClips.remove(audio); + } } } /** * Stops/Restores all currently playing sounds. * - * @param isMute mute or not currently playing sounds + * @param mute mute or not currently playing sounds */ public void setMute(boolean mute) { @@ -200,25 +211,36 @@ public class SoundNotificationHandlerImpl if (audioNotifService != null) { - Iterator<Map.Entry<SCAudioClip, NotificationData>> i - = playedClips.entrySet().iterator(); + List<SCAudioClip> clipsToStop = new ArrayList<SCAudioClip>(); - while (i.hasNext()) + synchronized(playedClips) { - Map.Entry<SCAudioClip, NotificationData> e = i.next(); + Iterator<Map.Entry<SCAudioClip, NotificationData>> i + = playedClips.entrySet().iterator(); - if (e.getValue() == data) + while (i.hasNext()) { - try - { - e.getKey().stop(); - } - finally + Map.Entry<SCAudioClip, NotificationData> e = i.next(); + + if (e.getValue() == data) { + clipsToStop.add(e.getKey()); i.remove(); } } } + + for(SCAudioClip clip : clipsToStop) + { + try + { + clip.stop(); + } + catch(Throwable t) + { + logger.error("Error stopping audio clip", t); + } + } } } @@ -246,7 +268,7 @@ public class SoundNotificationHandlerImpl { try { - Toolkit.getDefaultToolkit().beep(); + java.awt.Toolkit.getDefaultToolkit().beep(); return true; } catch (Throwable t) |