I want to play background music on iOS (Spotify, Music app, any other app …) and concurrently use the microphone as an input in Unity (using Microphone.Start).
Has anyone achieved that in Unity for iOS?
I can play music from the Music app and listen to another audio inside of the Unity app, thats working concurrently! But in the moment I initiate the microphone using Microphone.Start the background music stops. Also when the microphone was initialized and I start the background music again, in the moment I come back to the Unity app, the background audio will be muted.
Interestingly enough, it works out of the box on Android.
I found this Stackoverflow thread (ios - AVAudioSession configuration to record and play with others - Stack Overflow) and tried to add [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers error: nil]; [[AVAudioSession sharedInstance] setActive:YES withOptions: AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
to my UnityAppController but I had no success with it. Someone in the Stackoverflow thread has suggested to set automaticallyConfiguresApplicationAudioSession = false; for the AVCaptureSession but I’m not even sure if I can access the AVCaptureSession Unity is using to record the microphone, so I don’t know what else to do.
The first thing to find out is if iOS can even do this. Every time I do ANY application that uses the microphone, all audio is muted, so it might an iOS operating system assumption.
Best way to figure it out would be to make a Swift app in XCode and see if you can pull off what you want, keeping music going when microphone is enabled. If you can’t do it in Swift or ObjectionableC, you are unlikely to make Unity do it.
They are completely unrelated operating systems using completely different approaches to manage shared resources.
Thanks a lot for the answer!
I know apps on iOS which can do that. I also know one which was made with Unity which is capable of doing this, the name of this application is STAELLA.
Olá, não sou desenvolvedor. Eu quero deixar uma sugestão.
Muitos jogadores de Iphone têm um problema semelhante.
Com o MIC no jogo (Chat Voice in-game), o IOS baixa automaticamente o volume e muda o áudio dos aplicativos de fundo para o áudio mono. Nos jogos, precisamos nos comunicar com a equipe via chat de voz (MIC ON). Precisamos de áudio estéreo para tocar, para ouvir as instruções (esquerda / direita). Quando você liga o MIC, o jogo baixa automaticamente o volume e muda para o áudio MONO. Impossível tocar com áudio baixo e mono. É um problema com muitos usuários. Seria possível criar um App para resolver esse problema? O aplicativo seria um sucesso, pois muitos usuários de gamer mobile do iPhone precisam de ajuda com este problema.
@Soulside wow, thanks for that. Using NatDevice’s microphone class is working. There’s some kind of Audio crackeling which I need to investigate more, but in general I’m able to play music eg via Spotify and using the microphone inside of my app at the same time!
@Soulside sorry for this, I made a mistake while writing the text!
When using NatDevice I’m able to play music (Spotify, iTunes …) and using the microphone input inside of my app. So this problem is solved!
Given that NatDevice costs $30/mo, it may not be a workable solution for many.
I have opened case IN-76703 with Unity to resolve this bug. I’ll also note that AVProMovieCapture, which has a one-time fee, does not call StartMicrophone and does not pause external audio sources.