twilio / audioswitch

An Android audio management library for real-time communication apps.
Apache License 2.0
160 stars 49 forks source link

AudioDeviceChangeListener being invoked even after the AudioSwitch instance being nulled or stopped. #136

Closed AnonymousUserAndroid closed 1 year ago

AnonymousUserAndroid commented 1 year ago

Describe the bug Once the AudioSwitch listener is initialized, the method audioSwitch.start { audioDevices, selectedAudioDevice -> } keeps listening for new changes even after the audioSwitch instance is nulled or audioSwitch.stop() is called.

To Reproduce Steps to reproduce the behavior:

  1. Initiate the audioSwitch instance via code and then manually reassign it to null or call audioSwitch.stop().
  2. Run the app.
  3. Plug a wired headset or connect a bluetooth headset to the phone.
  4. Disconnect/unplug.
  5. Add debug breakpoint.
  6. See error.

Expected behavior The audioSwitch.start { audioDevices, selectedAudioDevice -> }listener should stop listening for new changes.

Actual behavior The audioSwitch.start { audioDevices, selectedAudioDevice -> } listener keeps listening for new changes even with audioSwitch instance is null.

AudioSwitch Version

Android Device (please complete the following information):

ocarevs commented 1 year ago

Hi @AnonymousUserAndroid I've looked into scenario where AudioSwitch is started then stopped and I do not see any listener callbacks with Wired or Bluetooth devices after stop() has been called. Can you provide code snippet or logs with AudioSwitch.loggingEnabled = true if you are still experiencing this issue. Regarding null scenario object is retained by the system, reassigning to null by itself after AudioSwitch is started it is not advisable and AudioSwitch.stop() should be called to close listeners/receivers and avoid memory leaks. Link