【问题标题】:Attempted to start an invalid broadcast session in live broadcasting using replaykit ios尝试使用 replaykit ios 在直播中启动无效的广播会话
【发布时间】:2019-11-29 12:39:25
【问题描述】:

我目前正在开发实时屏幕广播应用程序,该应用程序允许用户在 Youtube、Facebook、Mobcrush 之类的应用程序上分享他们的屏幕。一切正常,但有时广播会自动停止并抛出错误,每次我打开应用程序并在呈现 RPBroadcastActivityViewController 并选择应用程序后,所选应用程序的实时预览视图会自动关闭,RPBroadcastActivityViewController 也会自动关闭被解雇。另外,我无法启用麦克风。如果我启用麦克风,则会引发错误。

广播自动停止时出错 -

试图启动无效的广播会话

我尝试启用麦克风时出错 -

在开始录音之前必须先启用麦克风录音

我的代码:-

extension MainViewController: RPBroadcastActivityViewControllerDelegate {
    func broadcastActivityViewController(_ broadcastActivityViewController: RPBroadcastActivityViewController, didFinishWith broadcastController: RPBroadcastController?, error: Error?) {
        broadCastVC = broadcastController
        broadCastVC?.delegate = self

        broadcastActivityViewController.dismiss(animated: true) {
            guard error == nil else {
                return
            }

            broadCastVC?.startBroadcast(handler: { (error) in
                RPScreenRecorder.shared().delegate = self
                RPScreenRecorder.shared().isMicrophoneEnabled = true
                guard error != nil else {
                    return
                }
                print(stringVal: "Live :- Error:- \(error?.localizedDescription ?? "")")
            })
        }
    }
}


extension MainViewController: RPBroadcastControllerDelegate {
    func broadcastController(_ broadcastController: RPBroadcastController, didFinishWithError error: Error?) {
        guard error != nil else {
            return
        }
        print(stringVal: "Live :- Error while starting broadcast :- \(error?.localizedDescription ?? "")")

        if broadCastVC?.isBroadcasting == true {
            broadCastVC?.finishBroadcast(handler: { (error) in
            })
        }
    }
}

extension MainViewController: RPScreenRecorderDelegate { }


extension MainViewController {

    @IBAction func switchAudio(_ sender: Any) {
        let sharedRecorder = RPScreenRecorder.shared()
        sharedRecorder.isMicrophoneEnabled = self.audioSwitch.isOn
    }

    @IBAction func btnStartBroadCastAction(_ sender: UIButton) {
        if broadCastVC?.isBroadcasting == true {
            broadCastVC?.finishBroadcast(handler: { (error) in
            })
        } else {
            RPBroadcastActivityViewController.load(handler: { (broadCastACTVC, error) in
                if let broadcastAVC = broadCastACTVC {
                    broadcastAVC.delegate = self

                    if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.phone {
                        self.present(broadcastAVC, animated: true, completion: nil)
                    } else {
                        broadcastAVC.popoverPresentationController?.sourceView = self.btnBroadCast
                        broadcastAVC.modalPresentationStyle = UIModalPresentationStyle.formSheet
                        broadcastAVC.preferredContentSize = CGSize(width: self.view.frame.width, height: self.view.frame.height)
                        self.present(broadcastAVC, animated: true, completion: nil)
                    }
                }
            })
        }
    }
}

我找不到 ReplayKit 的任何文档。请帮我查找 ReplayKit 文档或任何可用的示例。

谢谢。

【问题讨论】:

  • 这有什么更新吗?当我尝试使用 finishBroadcastWithError 停止扩展时,出现了相同的错误“尝试启动无效...”。我将消息设置为“录制已停止”,但收到消息“尝试开始...”
  • 我尝试了很多摆脱,但我没有得到任何提示或解决方案。因此,我使用 youtube 和 Facebook 的 API 来进行直播。
  • 我还是一样。有人有什么吗?
  • 我认为这可能是一个 iOS 问题,因为它在 iOS 12 上运行良好。如果有人得到这个工作,那么请在此处发布解决方案。

标签: ios swift broadcast screensharing replaykit


【解决方案1】:

这意味着您的扩展程序在设置完成之前就崩溃了。使用菜单Debug > Attach to Process by PID or Name…,输入你的扩展进程的确切名称,等待它被设置(它应该出现在调试检查器下),然后开始你的广播会话。然后,您会在调试器中发现崩溃。

【讨论】:

    【解决方案2】:

    您应该检查您的扩展是否超过了 50mb 的内存限制。就我而言,我发现快速打字是内存警告的原因。

    苹果开发者论坛here有一些讨论内存问题,但目前没有官方回复。

    【讨论】:

    • 但我没有使用扩展,因为我直接将屏幕流式传输到 Facebook 和 youtube,所以
    猜你喜欢
    • 2016-12-17
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-02
    • 1970-01-01
    • 2016-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多