twilio / audioswitch

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

Chromecast and audioswitch #121

Open elayes211 opened 2 years ago

elayes211 commented 2 years ago

Is your feature request related to a problem? Please describe. The default audio routing behaviour of Android 11 and Android 12 makes me mad. In reality the audio routing is not working properly. I can change the audio output to the desired one but when I do that, after 1-2 seconds it switches back to default (AudioDeviceInfo.TYPE_REMOTE_SUBMIX in case of Chromecast).

Describe the solution you'd like I would like a way to make system wide audio routing to finally work, while casting my screen to a Chromecast/TV, this way I will be able to route the sound to my USB headset and turn my PC into an Android computer.

Describe alternatives you've considered I've tried using audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);, audioManager.setSpeakerphoneOn(true); and audioManager.setCommunicationDevice(setDevice);. I've also tried, but not enough, to disable the chromecast audio device by using setWiredDeviceConnectionState and reflection of java. I cannot find the correct parameters to pass and I am getting system errors. I've also tried MediaRecorder and routing of it's data directly to a device but Chromecast/TV Casting and MediaRecorder cannot work together, they stop each other.

Additional context Untitled