Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ExampleAVAudioEngineDevice to handle multiple incoming calls causes no sound issues #569

Open
alpha2048 opened this issue Oct 18, 2024 · 3 comments

Comments

@alpha2048
Copy link

Description

I'm trying to use ExampleAVAudioEngineDevice (for playing music during a call.)
When handling multiple incoming calls, it goes completely no sound (no voice, no music).

Steps to Reproduce

  1. set that AudioDevice.
TwilioVoiceSDK.audioDevice = exampleAVAudioEngineDevice
  1. set CXProvider Setting
        configuration.maximumCallGroups = 1
        configuration.maximumCallsPerCallGroup = 1
  1. receive the first incoming call, (there is no problem)
  2. receive the second incoming while on first call. When I answer, there is no sound.

Code

The relevant code is given below:

class TwilioHandler: NSObject, NotificationDelegate, CallDelegate {

    let exampleAudioDevice: ExampleAVAudioEngineDevice = ExampleAVAudioEngineDevice()

    required init() {
        TwilioVoiceSDK.audioDevice = exampleAVAudioEngineDevice
    }

    func handleDidReset() {
        exampleAudioDevice.isEnabled = false
    }
    func handleActivateAudioSession(audioSession: AVAudioSession) {
        exampleAudioDevice.isEnabled = true
    }
    func handleDeactivateAudioSession(audioSession: AVAudioSession) {
        exampleAudioDevice.isEnabled = false
    }

    func handleAnswer() {
        let session = AVAudioSession.sharedInstance()
        func trySetAudioSession() {
            do {
                try session.setCategory(.playAndRecord, mode: .voiceChat, options: [.allowBluetooth, .allowBluetoothA2DP])
                try session.setPreferredSampleRate(sampleRate)
                try session.setPreferredIOBufferDuration(ioBufferDuration)
                try session.setAggregatedIOPreference(.aggregated)
                if session.maximumInputNumberOfChannels > 0 {
                    try session.setPreferredInputNumberOfChannels(1)
                }
                if session.maximumOutputNumberOfChannels > 0 {
                    try session.setPreferredOutputNumberOfChannels(1)
                }
                try session.setActive(true)
            } catch {
            }
        }
        
        trySetAudioSession()
    }
}

Expected Behavior

voice/music correctly during second incoming call.

Actual Behavior

no sound during second incoming call.

Reproduces How Often

always, or frequently.

Twilio Call SID(s)

Logs

Versions

All relevant version information for the issue.

Voice iOS SDK

6.10.4

Xcode

16.0

iOS Version

15

iOS Device

iPhone7


BTW, Is AudioDeviceExample still being maintained?
Does anyone use ExampleAVAudioEngineDevice?

@bobiechen-twilio
Copy link
Contributor

Hi @alpha2048

Thanks for reaching out with the interesting use case. A couple of questions:

  • How did you interact with CallKit and the native call UI when you accepted the 2nd incoming call?
  • Did you see any error that could be the indication of the no-audio issue of the second call?

@alpha2048
Copy link
Author

@bobiechen-twilio

Thx for checking.

How did you interact with CallKit and the native call UI when you accepted the 2nd incoming call?

Press "End & Accept" to switch to the 2nd incoming call.

IMG_0001

Did you see any error that could be the indication of the no-audio issue of the second call?

No errors or crashes occur at this point.
But other incoming calls may result in no-audio after this.

@alpha2048
Copy link
Author

After this occurs, you may also experience the following crash:

Fatal Exception: NSInvalidArgumentException
The supplied context is invalid.
0  CoreFoundation                 0x92c60 __exceptionPreprocess
1  libobjc.A.dylib                0x14ee4 objc_exception_throw
2  CoreFoundation                 0x15d490 -[NSException init]
3  TwilioVoice                    0x6f18 TVOAudioDeviceExecuteWorkerBlock + 117 (TVOExternalAudioDevice.mm:117)
4  Runner                         0x963208 -[ExampleAVAudioEngineDevice handleRouteChange:] + 1046 (ExampleAVAudioEngineDevice.m:1046)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants