File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -214,14 +214,28 @@ class Application {
214214 Console . log ( " listChanged " , list)
215215
216216 if list. added. count > 0 {
217- let added = list. added [ 0 ]
218- selectOutput ( device: added)
217+ for added in list. added {
218+ if Output . isDeviceAllowed ( added) {
219+ selectOutput ( device: added)
220+ break
221+ }
222+ }
219223 } else if ( list. removed. count > 0 ) {
220- let removed = list. removed [ 0 ]
221- if ( removed. id != selectedDevice. id) {
222- stopEngines ( )
224+
225+ var currentDeviceRemoved = false
226+ for removed in list. removed {
227+ if removed. id == selectedDevice. id {
228+ currentDeviceRemoved = true
229+ break
230+ }
231+ }
232+
233+ stopEngines ( )
234+ if ( !currentDeviceRemoved) {
235+ try ! AudioDeviceEvents . recreateEventEmitters ( [ . isAliveChanged, . volumeChanged, . nominalSampleRateChanged] )
236+ self . setupDriverDeviceEvents ( )
223237 Utilities . delay ( 500 ) {
224- createAudioPipeline ( )
238+ createAudioPipeline ( )
225239 }
226240 }
227241 }
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ import EmitterKit
1313import AVFoundation
1414
1515class Output {
16+ static func isDeviceAllowed( _ device: AudioDevice ) -> Bool {
17+ return device. transportType != nil && Constants . SUPPORTED_TRANSPORT_TYPES. contains ( device. transportType!) && !device. isInputOnlyDevice ( )
18+ }
19+
1620 static var allowedDevices : [ AudioDevice ] {
1721 return AudioDevice . allOutputDevices ( )
1822 . filter ( { device in
@@ -21,7 +25,7 @@ class Output {
2125 return false
2226 }
2327 }
24- return device . transportType != nil && Constants . SUPPORTED_TRANSPORT_TYPES . contains ( device. transportType! )
28+ return isDeviceAllowed ( device)
2529 } )
2630 }
2731
Original file line number Diff line number Diff line change @@ -61,8 +61,11 @@ extension AudioDevice {
6161 self . setMute ( newValue, channel: 0 , direction: . playback)
6262 } else {
6363 Console . log ( self . channels ( direction: . playback) . intValue)
64- for channel in 1 ... self . channels ( direction: . playback) . intValue {
65- self . setMute ( newValue, channel: UInt32 ( channel) , direction: . playback)
64+ let channels = self . channels ( direction: . playback) . intValue
65+ if channels >= 1 {
66+ for channel in 1 ... self . channels ( direction: . playback) . intValue {
67+ self . setMute ( newValue, channel: UInt32 ( channel) , direction: . playback)
68+ }
6669 }
6770 }
6871 }
You can’t perform that action at this time.
0 commit comments