diff --git a/src/net/java/sip/communicator/impl/neomedia/MediaConfigurationImpl.java b/src/net/java/sip/communicator/impl/neomedia/MediaConfigurationImpl.java index 44e5cdf4b..b5a49ea64 100644 --- a/src/net/java/sip/communicator/impl/neomedia/MediaConfigurationImpl.java +++ b/src/net/java/sip/communicator/impl/neomedia/MediaConfigurationImpl.java @@ -261,6 +261,13 @@ public void itemStateChanged(ItemEvent e) captureCombo, capturePreview); } + else + { + audioLevelListenerThread.init( + audioSystem, + captureCombo, + capturePreview); + } } /** @@ -1031,18 +1038,18 @@ private class AudioLevelListenerThread /** * The audio system used to get and set the sound devices. */ - private final AudioSystem audioSystem; + private AudioSystem audioSystem; /** * The combo box used to select the device the user wants to use. */ - private final JComboBox comboBox; + private JComboBox comboBox; /** * The sound level indicator used to show the effectiveness of the * capture device. */ - private final SoundLevelIndicator soundLevelIndicator; + private SoundLevelIndicator soundLevelIndicator; /** * The buffer used for reading the capture device. @@ -1085,16 +1092,49 @@ public AudioLevelListenerThread( final AudioSystem audioSystem, final JComboBox comboBox, final SoundLevelIndicator soundLevelIndicator) + { + this.init(audioSystem, comboBox, soundLevelIndicator); + } + + /** + * Creates a new listener to combo box and affect changes to the audio + * level indicator. + * + * @param audioSystem The audio system used to get and set the sound + * devices. + * @param comboBox The combo box used to select the device the user + * wants to use. + * @param soundLevelIndicator The sound level indicator used to show the + * effectiveness of the capture device. + */ + public void init( + final AudioSystem audioSystem, + final JComboBox comboBox, + final SoundLevelIndicator soundLevelIndicator) { this.audioSystem = audioSystem; - this.comboBox = comboBox; - this.soundLevelIndicator = soundLevelIndicator; - this.runDeviceSession = new Thread(this); - this.runDeviceSession.start(); + // When this code is call to reinit the audio level indicator, then + // first remove old listeners for the combo box. + if(this.comboBox != null) + this.comboBox.removeActionListener(this); + this.comboBox = comboBox; if (comboBox != null) comboBox.addActionListener(this); + // When this code is call to reinit the audio level indicator, then + // first remove old listeners for the sound level indicator. + if(this.soundLevelIndicator != null) + { + HierarchyListener[] hierarchyListeners + = soundLevelIndicator.getHierarchyListeners(); + for(int i=0; i < hierarchyListeners.length; ++i) + { + soundLevelIndicator.removeHierarchyListener( + hierarchyListeners[i]); + } + } + this.soundLevelIndicator = soundLevelIndicator; soundLevelIndicator.addHierarchyListener( new HierarchyListener() { @@ -1115,6 +1155,13 @@ public void run() } } }); + + // Keeps the same single thread for the whole Jitsi session. + if(this.runDeviceSession == null) + { + this.runDeviceSession = new Thread(this); + this.runDeviceSession.start(); + } } /**