我正在使用Twilio可编程视频在音频聊天中连接两个用户。我想让用户可以选择在音频会话期间记录他们的屏幕,所以我正在使用Replaykit。一切正常,但Twilio启动后会立即切掉录音中的音频。

Twilio使用的音频类型和Replaykit音频捕获之间是否存在一些冲突?

在Twilio处于活动状态时尝试添加声音之前,我经历过类似的事情,一旦播放另一种声音,这将导致Twilio音频被切断。

编辑:我尝试了不同的方法,所以我只有最新的更改,但这是我用于ReplayKit的代码。这只是标准的“开始”,“停止”和“预览”记录。

func startRecording() {

    guard recorder.isAvailable else {
        print("Recording not available")
        return
    }

    recorder.isMicrophoneEnabled = true

    recorder.startRecording{ [unowned self] (error) in

        guard error == nil else {
            print("error starting the recording")
            return
        }

        print("Started Recording Successfully")

        self.isRecording = true
    }
}

func stopRecording() {

    recorder.stopRecording { [unowned self] (preview, error) in
        print("Stopped recording")

        guard preview != nil else {
            print("Preview controller not available")
            return
        }

        let alert = UIAlertController(title: "Recording Finished", message: "Would you like to edit or delete your recording?", preferredStyle: .alert)

        let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (action: UIAlertAction) in
            self.recorder.discardRecording(handler: { () -> Void in
                print("Recording suffessfully deleted.")
            })
        })

        let editAction = UIAlertAction(title: "Edit", style: .default, handler: { (action: UIAlertAction) -> Void in
            preview?.previewControllerDelegate = self
            self.present(preview!, animated: true, completion: nil)
        })

        alert.addAction(editAction)
        alert.addAction(deleteAction)
        self.present(alert, animated: true, completion: nil)

        self.isRecording = false
    }
}

func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
    dismiss(animated: true)
}


我也尝试过使用控制面板中的新录制功能。我可以从其他应用程序捕获音频,但是当Twilio在我的应用程序上启动时,录音中的音频将变为静音,并在Twilio停止时返回。这就是让我认为Twilio和Replaykit之间存在冲突的原因,但是也许有一种我不知道的捕获它的方法。

我也尝试使用.startCapture而不是.startRecording,但是我认为我使用的方式不正确,因此也找不到很多文档。

最佳答案

为了防止新的音频源中断先前的音频源,可以将其类别设置为“环境”:

 try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)


对于您的情况,我认为您应该将其应用于Twilio会议

关于ios - Replaykit和Twilio,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47514359/

10-14 21:55