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

Connecting to meeting while app is backgrounded fails if AVAudioSession .mixWithOthers option is enabled #614

Open
honeabh-amazon opened this issue Sep 22, 2023 · 0 comments

Comments

@honeabh-amazon
Copy link

Describe the bug
When the app's AVAudioSession has the .mixWithOthers or .interruptSpokenAudioAndMixWithOthers option enabled, and CallKit is not enabled, Chime SDK fails to connect to the meeting while the app is backgrounded with audioFailedToStart error (specifically when calling meetingSession.audioVideo.start()). Connecting in the foreground works fine. This bug occurs when trying to reconnect to the conference after an interruption from another audio source or phone call.

To Reproduce
Steps to reproduce the behavior:

  1. Enable .mixWithOthers option on the AVAudioSession
  2. Handle phone call interruptions by stopping the meeting session when the interruption starts, and starting the session again when the interruption ends.
  3. Call will fail with audioFailedToStart error

Expected behavior
Successfully connect to the meeting

Logs
2023-09-22 11:27:45.734040-0400 **redacted**[63175:18733445] [**redacted**][ChimeConferenceSession] - ERROR: Failed to reconnect to chime conference: audioFailedToStart (no additional information is logged about the error from the SDK)

Test environment Info (please complete the following information):

  • Device: iPhone 14
  • OS: iOS 16.3.1
  • Version AmazonChimeSDK: 20.0
  • Version AmazonChimeSDKMedia: 16.0
  • Can you reproduce this in the demo app? No

Additional context
One workaround that I've found is to use mono16k audio mode in the Chime SDK configuration. However, this is not acceptable for our use case which requests high fidelity audio

Example code for handling audio interruptions without CallKit:

/// Initializes NotificationCenter observers
    func initNotificationCenterObservers() {
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(handleInterruption),
            name: AVAudioSession.interruptionNotification,
            object: AVAudioSession.sharedInstance()
        )
    }

    /// Handles conference interruptions. More information
    @objc private func handleInterruption(notification: Notification) {
        guard let userInfo = notification.userInfo,
            let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt,
            let type = AVAudioSession.InterruptionType(rawValue: typeValue) else {
                return
        }

        if type == .began {
            meetingSession.audioVideo..stop()
        }
        if type == .ended {
            if let optionsValue = userInfo[AVAudioSessionInterruptionOptionKey] as? UInt {
                let options = AVAudioSession.InterruptionOptions(rawValue: optionsValue)
                let shouldResume = options.contains(.shouldResume)
                if (shouldResume) {
                    do {
                        try meetingSession.audioVideo.start()
                    } catch {
                        logger.error("Error reconnecting to meeting")
                    }
                }
            } else {
                logger.info("Interupption ended but iOS indicates that we should not resume")
            }
        }
    }
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

1 participant