Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity3D - Audio playing getting muted after getting any call/notification on Android

I have audio playing issue on Android build. I'm using Unity 5.4.0b15, but I had same issue on 5.3.4p3.

I have simple component for playing background music added to "AudioPlayer" GameObject in my scene.

public AudioClip clip;
private AudioSource _musicAudioSource;

private void Awake()
{
   if (_musicAudioSource == null)
   {
       _musicAudioSource = gameObject.AddComponent<AudioSource>();
   }
   _musicAudioSource.loop = true;
   _musicAudioSource.clip = clip;
   _musicAudioSource.Play();
}

After running game on Android devices the music starts playing perfectly. But while it running I'm getting any kind of notification or call (phone, viber or any other massinger) the music stops playing. Also all the other sounds playing getting muted, which I used in gameplay. The only way to restart playing audio is to kill application and run it again.

Also getting same muted issue, when I'm running game while listening any audio using native player, like Play Music.

On iOS everything works perfectly.

like image 587
Hayk Geghamyan Avatar asked Feb 08 '23 03:02

Hayk Geghamyan


1 Answers

This is definitely a bug in Unity. I bumped into the same problem and ran some tests to try to fix it but there is no way to recover the audio without restarting the app.

In my tests I used Google Hangouts notifications to kill the audio.

Programmer's proposed fix won't work because: 1. The notification does not trigger application pause nor application focus events. 2. Initializing a new AudioListener and/or AudioSource instances will not recover the audio either.

This is a low level bug in Unity. I will make a report on the bug.

like image 64
EdPS Avatar answered Feb 09 '23 15:02

EdPS