如何在CoreVideo直播流会话中添加交互式UIView(例如倒数计时器)

mkt*_*kto 6 core-video swift

我正在关注从iPhone启动Facebook直播会话的示例快速代码:

override func viewDidLoad() {
    super.viewDidLoad()

    liveButton.layer.cornerRadius = 15

    session = VCSimpleSession(videoSize: CGSize(width: 1280, height: 720), frameRate: 30, bitrate: 4000000, useInterfaceOrientation: false)
    contentView.addSubview(session.previewView)
    session.previewView.frame = contentView.bounds
    session.delegate = self
}

func startFBLive() {
    if FBSDKAccessToken.current() != nil {
        FBLiveAPI.shared.startLive(privacy: livePrivacy) { result in
            guard let streamUrlString = (result as? NSDictionary)?.value(forKey: "stream_url") as? String else {
                return
            }
            let streamUrl = URL(string: streamUrlString)

            guard let lastPathComponent = streamUrl?.lastPathComponent,
                let query = streamUrl?.query else {
                    return
            }

            self.session.startRtmpSession(
                withURL: "rtmp://rtmp-api.facebook.com:80/rtmp/",
                andStreamKey: "\(lastPathComponent)?\(query)"
            )

            self.livePrivacyControl.isUserInteractionEnabled = false
        }
    } else {
        fbLogin()
    }
}
Run Code Online (Sandbox Code Playgroud)

此代码将正确地将相机视频输入到Facebook.

但是,我应该如何覆盖UIView,例如摄像机Feed上的倒计时文本?我并不是说在手机上本地显示UIView,我的意思是将UIView叠加到视频源中,以便UIView流入Facebook Live流,并且其他设备上的其他直播观看者也可以看到.

我可以看到VCSimpleSession有这个方法:

addPixelBufferSource: (UIImage*) image
                     withRect: (CGRect) rect;
Run Code Online (Sandbox Code Playgroud)

但这可能不是我想要的,因为我需要添加一个倒计时文本......任何想法?

Viv*_*vek -2

当开始直播会话时

  • 在父视图上添加带有 UILabel 的 UIView(倒计时视图)。
  • UILabel 文本随计时器变化。
  • 必须是具有透明背景的 UIView(倒计时视图)。

也许你的问题会得到解决。

在此输入图像描述