Search Unity

Audio [iOS] - Mute Other Audio Sources

Discussion in 'Audio & Video' started by Annopolus, Oct 21, 2019.

  1. Annopolus

    Annopolus

    Joined:
    Apr 15, 2015
    Posts:
    18
    Initializing microphone on iOS cause any background music stops (ie. from Spotify).

    I wrote music visualization app, which listens audio on MIC and is doing some gfx.
    On Android works perfect. App can listen external audio and audio from the same phone in the background.
    On iOS my app can listen only external audio. It's impossible to listen internal music through MIC, because my app when initializes MIC force to stop background music.

    Player's option "Mute Other Audio Sources" is un-checked.

    I met this problem almost a year ago. It was an issue registered: https://issuetracker.unity3d.com/is...07.1290472253.1571412449-149673108.1514931261
    and it's status is fixed.

    From my perspective the only fix is related that launching app kills background music. Now, I can launch an app and background music plays but until MIC initialization will happen.

    I'm using Unity 2019.2.9f1 and got the problem also through the previous versions.

    MIC initialization via method EnableMicrophone:

    Code (CSharp):
    1.     IEnumerator WaitForMicrophone()
    2.     {
    3.         while (!(Microphone.GetPosition(null) > 0))
    4.         {
    5.             yield return null;
    6.         }
    7.     }
    8.  
    9.     public void EnableMicrophone()
    10.     {
    11.         AudioSource snd = GetComponent<AudioSource>();
    12.         snd.clip = Microphone.Start(null, true, 1, 48000);
    13.         snd.loop = true;
    14.  
    15.         WaitForMicrophone();
    16.  
    17.         snd.Play();
    18. }
     
  2. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,305
    you most likely have to modify AVAudioSession unity uses (fmod afaik doesn't modify session, but unity sets it up)
     
  3. Annopolus

    Annopolus

    Joined:
    Apr 15, 2015
    Posts:
    18
    thomas_unity695 and r618 like this.
  4. nikrath

    nikrath

    Joined:
    Jun 25, 2013
    Posts:
    2
  5. Soulside

    Soulside

    Joined:
    Nov 1, 2018
    Posts:
    30
    Hey guys, we had similar problems with the Unity Engine Microphone class.
    We use Unity 2021.1.2f1 version.
    We tried different combinations with the Project Settings to let the background audio play on iOS when the User starts to record the audio. Nothing helped.

    Yesterday we bought the NatDevice plugin from asset store to solve another problem on iOS. When the recording is started it takes about a second on iOS to actually start. I mean the Microphone.Start() method. On Android it starts instantly.

    With the NatDevice plugin both problems are solved. The audio keeps playing in background when you start to record. And there is also no delay when the recording is started. BTW you need to initialize the AudioDevice of the plugin in advance, because on iOS the initialization takes about a second.
    If you think the plugin is to expensive, you can try implement it yourself. As I know it uses the AVAudioEngine internally on iOS. You can read through the docs of the plugin, it will give you some useful hits.
     
    jpingen likes this.
  6. marvpaul

    marvpaul

    Joined:
    May 9, 2016
    Posts:
    32
    @Soulside I can confirm using microphone while play music on your iOS device (spotify / iTunes ...) works with NatDevice!
     
    Soulside likes this.