Closed velevtzvetlin closed 1 year ago
would it make sense to call enumerateDevices before setting up the listeners? https://github.com/twilio/audioswitch/blob/ac4900b2a507828c1b67fa3717b82b9aed23fb4f/audioswitch/src/main/java/com/twilio/audioswitch/AudioSwitch.kt#L162
I am also getting the same exception
Fatal Exception: java.util.ConcurrentModificationException
TwilioCallService$$ExternalSyntheticLambda1.invoke (Unknown Source:6)
com.twilio.audioswitch.AudioSwitch.enumerateDevices (AudioSwitch.kt:307)
com.twilio.audioswitch.AudioSwitch.enumerateDevices$default (AudioSwitch.kt:270)
com.twilio.audioswitch.AudioSwitch$bluetoothDeviceConnectionListener$1.onBluetoothHeadsetActivationError(AudioSwitch.kt:60)
com.twilio.audioswitch.bluetooth.BluetoothHeadsetManager$EnableBluetoothScoJob.scoTimeOutAction (BluetoothHeadsetManager.kt:332)
com.twilio.audioswitch.bluetooth.BluetoothScoJob$BluetoothScoRunnable.run (BluetoothScoJob.kt:57)
I am using Android Service, iterating audio devices as bluetooth is not get connected automatically so manually setting it, code is below:
List<AudioDevice> availableAudioDevices;
private AudioSwitch audioSwitch;
@Override
public void onCreate() {
super.onCreate();
audioSwitch = new AudioSwitch(getApplicationContext(), false, focusChange -> {
}, preferredDevices);
audioSwitch.start((audioDevices, audioDevice) -> {
String selectedDeviceName = audioDevice.getName();
for (AudioDevice device : audioDevices) {
if ( selectedDeviceName == device.getName() ) {
switch (selectedDeviceName) {
case "Speakerphone":
FirebaseCrashlytics.getInstance().log("audioDevices "+ audioDevices);
try{
if ( audioDevices.size() > 2 ) {
audioSwitch.selectDevice(audioDevices.get(audioDevices.size() - 1));
} else {
audioSwitch.selectDevice(audioDevices.get(1));
}
}catch (Exception e){
FirebaseCrashlytics.getInstance().log(e.getMessage());
audioSwitch.selectDevice(audioDevices.get(0));
}
break;
default:
audioSwitch.selectDevice(audioDevices.get(0));
break;
}
}
}
return Unit.INSTANCE;
});
availableAudioDevices = audioSwitch.getAvailableAudioDevices();
// Log.d(TAG,"ff- >>" + gson.toJson(availableAudioDevices));
audioSwitch.selectDevice(availableAudioDevices.get(0));
}
getting runtime exception at while iterating for audioDevices
`for(AudioDevice device : audioDevices)
`
This issue has been resolved as part of https://github.com/twilio/audioswitch/pull/142
audioSwitch.start(...)
audioSwitch.stop
make call right after pulling headphones. =>
audioSwitch.start(...)
seems like
enumerateDevices
is called twice possibly? once byaudioSwitch.start()
and a also bywiredDeviceConnectionListener