CRASH: AudioTrack::setVolume

We solved this, it was only an issue on Xiaomi devices Android 11 (but we had a loooot of crashes reported). We changed the Audio output for these devices to FMOD.OUTPUTTYPE.OPENSL. Before we had automatic audio output selection, so it decided based on android version to take Open SL, AudioTrack or AAudio. And now we just override the automatic selection for the offending devices. So the issue was related to Xiaomi changing android OS or screwing up driver code… The code I provided was added to FMOD.AudioManager.Initialize() method. You can maybe expect a little more latency, since AAudio that was choosen before is supposed to work with less latency. Otherwise all seems well.

#if UNITY_ANDROID

var deviceModel = SystemInfo.deviceModel;
if (!string.IsNullOrEmpty(deviceModel) && deviceModel.Contains("M2003J15SC") || deviceModel.Contains("M2004J19C") || deviceModel.Contains("M2101K7BG") || deviceModel.Contains("21121119SG") || deviceModel.Contains("M2101K7BL"))
{
    using var buildVersion = new AndroidJavaClass("android.os.Build$VERSION");
    var sdkVersion = buildVersion.GetStatic<int>("SDK_INT");

    if (sdkVersion == 31)
    {
        outputType =  FMOD.OUTPUTTYPE.OPENSL;
        RuntimeUtils.DebugLogWarning($"Disabling sound on, because of bad drivers and crashes on {deviceModel}");
    }
}
#endif