Skip to content

Instantly share code, notes, and snippets.

@pixlhero
Created December 13, 2023 09:04
Show Gist options
  • Save pixlhero/3d370dcdbcfaefa4df12138161307da4 to your computer and use it in GitHub Desktop.
Save pixlhero/3d370dcdbcfaefa4df12138161307da4 to your computer and use it in GitHub Desktop.
Echo cancellation workaround iOS
using System.Runtime.InteropServices;
using UnityEngine;
public static class AVAudioSession
{
[DllImport("__Internal")]
private static extern void _SetupAudioModeForVideoCall();
public static void SetupAudioModeForVideoCall()
{
if (UnityEngine.Application.platform == RuntimePlatform.IPhonePlayer)
{
_SetupAudioModeForVideoCall();
}
}
}
#import <AVFAudio/AVAudioSession.h>
extern "C" void _SetupAudioModeForVideoCall(){
// Retrieve the shared audio session
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *error = nil;
// Set the audio session category and mode
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord mode:AVAudioSessionModeVideoChat options:0 error:&error];
if (error) {
NSLog(@"Failed to set the audio session configuration: %@", error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment