# Delay over Bluetooth with Fmod api 1.09.06 on android

**URL:** <https://qa.fmod.com/t/delay-over-bluetooth-with-fmod-api-1-09-06-on-android/13421>\
**Category:** FMOD Studio\
**Created:** [September 11, 2017, 3:56pm UTC](https://qa.fmod.com/t/delay-over-bluetooth-with-fmod-api-1-09-06-on-android/13421 "2017-09-11T15:56:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![talpa](https://avatars.discourse-cdn.com/v4/letter/t/97f17d/32.png) [@talpa](https://qa.fmod.com/u/talpa)\
**Post date:** [September 11, 2017, 3:56pm UTC](https://qa.fmod.com/t/delay-over-bluetooth-with-fmod-api-1-09-06-on-android/13421/1 "2017-09-11T15:56:18Z")

</div>

hi,

sorry for my English,  
im developed car engine sound in Fmod Studio …  
right now im using the build in car engine sound from the examples from Vehicles  
integrated to my android app…

im having a audio delay of 2-3 sec over Bluetooth in a few cars in A2DP protocol.  
i have checked my app over couple of phones nexus 6p, nexus 5x , android 8.0, galaxy s7 , android 7.1 (same delay)…

i saw in the website that there is an update soon (1.09.07), maybe the fix is on its way…  
or maybe im doing something wrong, im not doing nothing to route the audio output( speaker, aux, bluetooth and etc…) and maybe i should.

i just calling the rpm value parameter from the car event and change  
its value with a slider in a loop…

in speaker(phone) and aux (cable direct to the audio system) the sound works perfectly…  
in Bluetooth there is a problem- delay of 2-3 sec.

please help,  
thanks  
tal

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [September 12, 2017, 12:22am UTC](https://qa.fmod.com/t/delay-over-bluetooth-with-fmod-api-1-09-06-on-android/13421/2 "2017-09-12T00:22:19Z")

</div>

Hi Tal,

Unfortunately, bluetooth lag on Android devices is a common issue and is unrelated to FMOD. This is something that needs to be fixed by Android.

Thanks,  
Richard

---

<div class="post-metadata">

**Author:** ![talpa](https://avatars.discourse-cdn.com/v4/letter/t/97f17d/32.png) [@talpa](https://qa.fmod.com/u/talpa)\
**Post date:** [September 12, 2017, 3:55pm UTC](https://qa.fmod.com/t/delay-over-bluetooth-with-fmod-api-1-09-06-on-android/13421/3 "2017-09-12T15:55:22Z")

</div>

> [@](#):
>
> Hi Tal,
> 
> Unfortunately, bluetooth lag on Android devices is a common issue and is unrelated to FMOD. This is something that needs to be fixed by Android.
> 
> Thanks,  
> Richard

hi,

Ok , i will try to figure it out from the android system aspect…  
i have another problem in some of the bluetooth devices…  
when the bluetooth is connected, and the sound is played  
i can hear the sound disrupted , not clean , broken, not fluid.

what can i do to fix this issue?

thanks

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [September 13, 2017, 12:05am UTC](https://qa.fmod.com/t/delay-over-bluetooth-with-fmod-api-1-09-06-on-android/13421/4 "2017-09-13T00:05:00Z")

</div>

Hello Tal,

There are situations with newer Android devices when if a bluetooth device is connected it can cause the audio to sound corrupted. Please try the following code which will detect if a bluetooth device is connected and set FMOD’s output type to audiotrack.

```
// check for bluetooth headset on android N (or above)
try
{
#if UNITY_ANDROID && !UNITY_EDITOR
int androidVersion = -1;
AndroidJavaClass buildClass = new AndroidJavaClass("android.os.Build$VERSION");
androidVersion = buildClass.GetStatic<int>("SDK_INT");

if (androidVersion >= 24)
{
bool bluetoothAudioIsOn = false;

AndroidJavaClass playerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = playerClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass audioManagerClass = new AndroidJavaClass("android.media.AudioManager");
AndroidJavaObject audioManager = activity.Call<AndroidJavaObject>("getSystemService", audioManagerClass);

bool isBluetoothA2dpOn = audioManager.Call<bool>("isBluetoothA2dpOn");
bool isBluetoothScoOn = audioManager.Call<bool>("isBluetoothScoOn");
bluetoothAudioIsOn = isBluetoothA2dpOn || isBluetoothScoOn;

if (bluetoothAudioIsOn)
{
result = lowlevelSystem.setOutput(FMOD.OUTPUTTYPE.AUDIOTRACK);
CheckInitResult(result, "Set output");
}
}
#endif
}
catch (Exception e)
{
Debug.LogWarning("Unable to determine android version or bluetooth status. Output is set to default.");
}

```

Please note this code will only work if the bluetooth device is connected _before_ launching the FMOD application. If you wanted, you could also use the same detection to provide a suggestion to users to not use bluetooth headphones.

Thanks,  
Richard

---

<div class="post-metadata">

**Author:** ![talpa](https://avatars.discourse-cdn.com/v4/letter/t/97f17d/32.png) [@talpa](https://qa.fmod.com/u/talpa)\
**Post date:** [September 13, 2017, 6:25am UTC](https://qa.fmod.com/t/delay-over-bluetooth-with-fmod-api-1-09-06-on-android/13421/5 "2017-09-13T06:25:18Z")

</div>

> [@](#):
>
> Hello Tal,
> 
> There are situations with newer Android devices when if a bluetooth device is connected it can cause the audio to sound corrupted. Please try the following code which will detect if a bluetooth device is connected and set FMOD’s output type to audiotrack.
> 
> ```
> // check for bluetooth headset on android N (or above)
> try
> {
> #if UNITY_ANDROID && !UNITY_EDITOR
> int androidVersion = -1;
> AndroidJavaClass buildClass = new AndroidJavaClass("android.os.Build$VERSION");
> androidVersion = buildClass.GetStatic<int>("SDK_INT");
> 
> if (androidVersion >= 24)
> {
> bool bluetoothAudioIsOn = false;
> 
> AndroidJavaClass playerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
> AndroidJavaObject activity = playerClass.GetStatic<AndroidJavaObject>("currentActivity");
> AndroidJavaClass audioManagerClass = new AndroidJavaClass("android.media.AudioManager");
> AndroidJavaObject audioManager = activity.Call<AndroidJavaObject>("getSystemService", audioManagerClass);
> 
> bool isBluetoothA2dpOn = audioManager.Call<bool>("isBluetoothA2dpOn");
> bool isBluetoothScoOn = audioManager.Call<bool>("isBluetoothScoOn");
> bluetoothAudioIsOn = isBluetoothA2dpOn || isBluetoothScoOn;
> 
> if (bluetoothAudioIsOn)
> {
> result = lowlevelSystem.setOutput(FMOD.OUTPUTTYPE.AUDIOTRACK);
> CheckInitResult(result, "Set output");
> }
> }
> #endif
> }
> catch (Exception e)
> {
> Debug.LogWarning("Unable to determine android version or bluetooth status. Output is set to default.");
> }
> 
> ```
> 
> Please note this code will only work if the bluetooth device is connected _before_ launching the FMOD application. If you wanted, you could also use the same detection to provide a suggestion to users to not use bluetooth headphones.
> 
> Thanks,  
> Richard

Hi,  
I’m using native Android (Java), and cpp (c++) native for fmod  
So the check for bscoOn and the ba2dp is on for the n and above I will do in java  
The low level is the same code for c++  
Thnks

---

<div class="post-metadata">

**Author:** ![talpa](https://avatars.discourse-cdn.com/v4/letter/t/97f17d/32.png) [@talpa](https://qa.fmod.com/u/talpa)\
**Post date:** [September 13, 2017, 9:51am UTC](https://qa.fmod.com/t/delay-over-bluetooth-with-fmod-api-1-09-06-on-android/13421/6 "2017-09-13T09:51:00Z")

</div>

update,

thanks it worked for me…  
the lag of the Bluetooth is still happening,  
there is no mode to work with low latency in FMOD to make it happen without the lag…

to check the latency over bluetooth im using the drrickorang LoopBack app,  
and the bluetooth device that cause me the problem (lag) says it take 10ms (loopback ), its the same latency with the bluetooth device without the issue/lag.

maybe there is a some configuration in fmod to solve this issue .

also, i have noticed the var isBluetoothA2dpOn return true from bluetooth with the lag and isBluetoothScoO return false.

thanks,  
tal

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [September 18, 2017, 5:09am UTC](https://qa.fmod.com/t/delay-over-bluetooth-with-fmod-api-1-09-06-on-android/13421/7 "2017-09-18T05:09:47Z")

</div>

Hi Tal,

We will take a look into bluetooth on Android in future releases however, there isn’t anything that can be done at the moment unfortunately.

Thanks,  
Richard
