首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >切换视频源Agora.io

切换视频源Agora.io
EN

Stack Overflow用户
提问于 2021-03-30 11:03:14
回答 2查看 163关注 0票数 0

我的agora应用程序有一个自定义的视频源,即我使用ARVideoKit传输的ARView。如何实现切换到前置摄像头?

我最初的想法是设置本地视频,但它什么也做不了

代码语言:javascript
复制
@objc private func switchCamera() {
    captureType = captureType == .ar ? .camera : .ar
    setCaptureType(to: captureType)
}

private func stopScene(){
    arRecorder.rest()
    sceneView.session.pause()
}

private func startScene() {        
    sceneView.session.run(configuration)
    arRecorder.prepare(configuration)
}

private func setCaptureType(to type: CaptureType) {
switch type {
case .ar:
    startScene()
    agoraKit.disableVideo()
    agoraKit.setVideoSource(arVideoSource)
    
case .camera:
    stopScene()
    
    agoraKit.enableVideo()
    agoraKit.setVideoSource(nil)
    let videoCanvas = AgoraRtcVideoCanvas()
    videoCanvas.uid = 0
    videoCanvas.renderMode = .hidden
    videoCanvas.view = localVideoView
    agoraKit.setupLocalVideo(videoCanvas)
}}

基本上,我需要停止ARSession,可能需要删除自定义视频源,并将本地视频设置为输入。

为了将ARView设置为视频源,我遵循了this tutorial

EN

回答 2

Stack Overflow用户

发布于 2021-04-08 04:18:40

您不需要切换Agora的摄像头源,而是应该更新ARKit配置以使用前置摄像头

代码语言:javascript
复制
class ViewController: UIViewController, ARSCNViewDelegate, RenderARDelegate, RecordARDelegate {
  weak var cameraFlipBtn : UIButton!
  enum cameraFacing {
      case front
      case back
  }
  var activeCam: cameraFacing = .back
  override func viewDidLoad() {
    super.viewDidLoad()
    // Configure ARKit Session
    let configuration = ARWorldTrackingConfiguration()
    configuration.planeDetection = [.horizontal, .vertical]
    self.activeCam = .back // set the active camera
    // Reverse camera button
    if ARFaceTrackingConfiguration.isSupported {
      // add reverse camera button
      let reverseCameraBtn = UIButton()
      reverseCameraBtn.frame = CGRect(x: self.view.bounds.maxX-75, y: 25, width: 50, height: 50)
      if let imageReverseCameraBtn = UIImage(named: "cameraFlip") {
          reverseCameraBtn.setImage(imageReverseCameraBtn, for: .normal)
      }
      self.view.insertSubview(reverseCameraBtn, at: 3)
      self.cameraFlipBtn = reverseCameraBtn
    }
    self.cameraFlipBtn.addTarget(self, action: #selector(switchCamera), for: .touchDown)
  }
  @objc private func switchCamera() {
    if self.activeCam == .back {
      // switch to front config
      let configuration = ARFaceTrackingConfiguration()
      configuration.isLightEstimationEnabled = true
      // run the config to swap the camera
      self.sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
      self.activeCam = .front
    } else {
      // switch to back cam config
      let configuration = ARWorldTrackingConfiguration()
      configuration.planeDetection = [.horizontal, .vertical]
      // run the config to swap the camera
      self.sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
      self.activeCam = .back
    }
  }
}
票数 2
EN

Stack Overflow用户

发布于 2021-04-01 18:06:21

不是enableVideo()/disableVideo()视频,而是尝试:

代码语言:javascript
复制
self.agoraKit.enableLocalVideo(true/false)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66864237

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档