AndroidAudioInAEC: UnityEngine.AndroidJavaException: java.lang.UnsupportedOperationException: Cannot

We are having issues with starting a multiplayer game. There is an error AndroidAudioInAEC: UnityEngine.AndroidJavaException: java.lang.UnsupportedOperationException: Cannot create AudioRecord.

This seems to happen after Unity popups permission for Recording Audio and accepting it.

Are there potential culprits and workaround for this issue?


The following are the setup information :

  • Photon Voice 2 Version: 2.27.1 or 1.23
  • Photon PUN 2 Version: 2.26.2
  • Unity Version: 2020.3.19f1
  • Device: Oculus Quest
  • Microphone Type: Unity


10-28 17:18:52.291 7701 7723 E Unity  : [Voice.Recorder] 2021-10-28T09:18:52:[PV] AndroidAudioInAEC: UnityEngine.AndroidJavaException: java.lang.UnsupportedOperationException: Cannot create AudioRecord

10-28 17:18:52.291 7701 7723 E Unity  :  at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0

10-28 17:18:52.291 7701 7723 E Unity  :  at UnityEngine.AndroidJNISafe.CallBooleanMethod (System.IntPtr obj, System.IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <00000000000000000000000000000000>:0

10-28 17:18:52.291 7701 7723 E Unity  :  at UnityEngine.AndroidJavaObject._Call[ReturnType] (System.String methodName, System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0

10-28 17:18:52.291 7701 7723 E Unity  :  at Photon.Voice.Unity.AndroidAudioInAEC..ctor (Photon.Voice.ILogger logger, System.Boolean enableAEC, System.Boolean enableAGC, System.Boolean enableNS) [0x00000] in <00000000000000000000000000000000>:0

10-28 17:18:52.291 7701 7723 E Unity  :  at Photon.Voice.Unity.Recorder.CreateLocalVoiceAudioAndSource () [0x00000] in <00000000000000000000000000000000>:0

10-28 17:18:52.291 7701 7723 E Unity  :  at Photon.Voice.Unity.Recorder.Setup () [0x00000] in <00000000000000000000000000000000>:0

10-28 17:18:52.291 7701 7723 E Unity  :  at Photon.Voice.

10-28 17:18:52.292 7701 7723 E Unity  : [Voice.Recorder] 2021-10-28T09:18:52:Photon microphone input source creation failure: UnityEngine.AndroidJavaException: java.lang.UnsupportedOperationException: Cannot create AudioRecord

10-28 17:18:52.292 7701 7723 E Unity  :  at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0

10-28 17:18:52.292 7701 7723 E Unity  :  at UnityEngine.AndroidJNISafe.CallBooleanMethod (System.IntPtr obj, System.IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <00000000000000000000000000000000>:0

10-28 17:18:52.292 7701 7723 E Unity  :  at UnityEngine.AndroidJavaObject._Call[ReturnType] (System.String methodName, System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0

10-28 17:18:52.292 7701 7723 E Unity  :  at Photon.Voice.Unity.AndroidAudioInAEC..ctor (Photon.Voice.ILogger logger, System.Boolean enableAEC, System.Boolean enableAGC, System.Boolean enableNS) [0x00000] in <00000000000000000000000000000000>:0

10-28 17:18:52.292 7701 7723 E Unity  :  at Photon.Voice.Unity.Recorder.CreateLocalVoiceAudioAndSource () [0x00000] in <00000000000000000000000000000000>:0

10-28 17:18:52.292 7701 7723 E Unity  :  at Photon.Voice.Unity.Recorder.Setup () [0x00000] in <000000000000000000000000000000

10-28 17:18:52.293 7701 7723 E Unity  : [Voice.Recorder] 2021-10-28T09:18:52:Local input source setup and voice stream creation failed. No recording or transmission will be happening. See previous error log messages for more details.

10-28 17:18:52.293 7701 7723 E Unity  : Photon.Voice.Unity.VoiceConnection:StartInitializedRecorders()

10-28 17:18:52.293 7701 7723 E Unity  : Photon.Voice.Unity.VoiceConnection:OnVoiceStateChanged(ClientState, ClientState)

10-28 17:18:52.293 7701 7723 E Unity  : Photon.Voice.PUN.PhotonVoiceNetwork:OnVoiceStateChanged(ClientState, ClientState)

10-28 17:18:52.293 7701 7723 E Unity  : System.Action`2:Invoke(T1, T2)

10-28 17:18:52.293 7701 7723 E Unity  : Photon.Realtime.LoadBalancingClient:GameEnteredOnGameServer(OperationResponse)

10-28 17:18:52.293 7701 7723 E Unity  : Photon.Realtime.LoadBalancingClient:OnOperationResponse(OperationResponse)

10-28 17:18:52.293 7701 7723 E Unity  : ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(StreamBuffer)

10-28 17:18:52.293 7701 7723 E Unity  : ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()

10-28 17:18:52.293 7701 7723 E Unity  : ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()

10-28 17:18:52.293 7701 7723 E Unity  : Photon.Voice.Unity.VoiceConnection:Dispatch()

Answers

  • Hi @hdavid_bpg,

    The exception is probably due to timing of permission granting vs. starting to access the microphone: the solution is to request permission first and only after it's granted start recording. See "Assets\Photon\PhotonVoice\Code\UtilityScripts\MicrophonePermission.cs" as example of how to do this, attach it to the same GameObject as the Recorder.

    This exception is happening with Photon microphone type so either that's what you set or that's a fallback (see Recorder.UseMicrophoneTypeFallback) because Unity microphone type failed first.

    Side notes:

    Please do not use Photon Voice Classic or PUN Classic anymore.

    Also, not sure why PUN 2 version is 2.26.2? Latest Photon Voice 2 (2.27.1) should have latest PUN 2 included (2.39).

    If you are starting your project now, please consider Photon Fusion (as PUN2 & Bolt are legacy replaced w/ Fusion) and we also provide Photon Voice integration with it.