App crashed when device connects to bluetooth

Hi, I have a simple audio application on Android that play the selected audio with AudioSource and AudioSourcePlayer.
Everything works fine until i connect (sometimes disconnect) the device to an external bluetooth headset when the app crashed, here’s the trace:

It seems like a buffer problem (The buffer size changed i guess) to me. Is there a way to prevent this from happening? Thank for any help